Skip to content

Error: Component in a collection does not show up in the JSON #11542

@Kinbaum

Description

@Kinbaum

v4 Beta Reproduction

I'm trying out the new v4 beta and have come across an issue. When you have a component type in the model of a collection, the data does not show up.

To reproduce this:

  1. Create a card collection with the model below
  2. Create a link component with the model below
  3. Enable find and findOne permission on the card collection
  4. Populate the card with some information
  5. Visit http://localhost:1337/api/cards
Card Collection
{
    "kind": "collectionType",
    "collectionName": "cards",
    "info": {
        "singularName": "card",
        "pluralName": "cards",
        "displayName": "Card"
    },
    "options": {
        "draftAndPublish": true
    },
    "pluginOptions": {
        "i18n": {
            "localized": true
        }
    },
    "attributes": {
        "title": {
            "pluginOptions": {
                "i18n": {
                    "localized": true
                }
            },
            "type": "string"
        },
        "description": {
            "pluginOptions": {
                "i18n": {
                    "localized": true
                }
            },
            "type": "text"
        },
        "ctas": {
            "type": "component",
            "repeatable": true,
            "pluginOptions": {
                "i18n": {
                    "localized": true
                }
            },
            "component": "generic.link"
        }
    }
}
Link Component
{
    "collectionName": "components_generic_links",
    "info": {
        "displayName": "Link",
        "icon": "link"
    },
    "options": {},
    "attributes": {
        "children": {
            "type": "string"
        },
        "href": {
            "type": "string"
        },
        "target": {
            "type": "enumeration",
            "enum": [
                "_blank",
                "_self",
                "_parent",
                "_top"
            ]
        }
    }
}

Expected behavior

I would expect to see the all of the data show up in the JSON when I visit http://localhost:1337/api/cards. However I do not see the ctas key in my JSON response. Here is the output:

{
    "data": [
        {
            "id": 1,
            "attributes": {
                "title": "Testing",
                "description": "Lorem ipsum",
                "createdAt": "2021-11-10T12:35:21.977Z",
                "updatedAt": "2021-11-10T12:38:45.189Z",
                "publishedAt": "2021-11-10T12:35:32.484Z",
                "locale": "en"
            }
        }
    ],
    "meta": {
        "pagination": {
            "page": 1,
            "pageSize": 25,
            "pageCount": 1,
            "total": 1
        }
    }
}

v3 Similar Issue

I have a similar problem in v3, but it's one that deals with dynamic zones. Have a look at the following models:

Member Collection
{
    "kind": "collectionType",
    "collectionName": "members",
    "info": {
        "name": "Member",
        "description": ""
    },
    "options": {
        "increments": true,
        "timestamps": true,
        "draftAndPublish": true
    },
    "pluginOptions": {
        "i18n": {
            "localized": true
        }
    },
    "attributes": {
        "slug": {
            "pluginOptions": {
                "i18n": {
                    "localized": true
                }
            },
            "type": "string"
        },
        "zone": {
            "pluginOptions": {
                "i18n": {
                    "localized": true
                }
            },
            "type": "dynamiczone",
            "components": [
                "generic.cards"
            ]
        }
    }
}
Card Component
{
    "collectionName": "components_generic_cards",
    "info": {
        "name": "Cards",
        "icon": "th-list",
        "description": ""
    },
    "options": {},
    "attributes": {
        "header": {
            "type": "string"
        },
        "cards": {
            "collection": "card"
        }
    }
}
Card Collection
{
    "kind": "collectionType",
    "collectionName": "cards",
    "info": {
        "name": "Card",
        "description": ""
    },
    "options": {
        "increments": true,
        "timestamps": true,
        "draftAndPublish": true
    },
    "pluginOptions": {
        "i18n": {
            "localized": true
        }
    },
    "attributes": {
        "title": {
            "pluginOptions": {
                "i18n": {
                    "localized": true
                }
            },
            "type": "string"
        },
        "description": {
            "pluginOptions": {
                "i18n": {
                    "localized": true
                }
            },
            "type": "text"
        },
        "ctas": {
            "type": "component",
            "repeatable": true,
            "pluginOptions": {
                "i18n": {
                    "localized": true
                }
            },
            "component": "generic.link"
        }
    }
}
Link Component
{
    "collectionName": "components_generic_links",
    "info": {
        "name": "Link",
        "icon": "link",
        "description": ""
    },
    "options": {},
    "attributes": {
        "children": {
            "type": "string",
            "required": true
        },
        "href": {
            "type": "string",
            "required": true
        },
        "target": {
            "type": "enumeration",
            "enum": [
                "_blank",
                "_self",
                "_parent",
                "_top"
            ]
        }
    }
}  

After I fill out some information in the both the card collection and member collection, then visit http://localhost:1337/members I do not see the ctas key below the cards in my JSON response. Here is the output:

[
    {
        "id": 1,
        "slug": "/member",
        "locale": "en",
        "published_at": "2021-11-09T21:25:51.000Z",
        "created_at": "2021-11-09T19:12:22.000Z",
        "updated_at": "2021-11-09T21:25:52.000Z",
        "zone": [
            {
                "__component": "generic.cards",
                "id": 5,
                "header": "My Header",
                "cards": [
                    {
                        "id": 3,
                        "title": "Testing",
                        "description": "Lorem ipsum",
                        "locale": "en",
                        "published_at": "2021-11-08T20:07:26.000Z",
                        "created_at": "2021-11-08T13:50:14.000Z",
                        "updated_at": "2021-11-09T23:45:39.000Z"
                    }
                ]
            }
        ],
        "localizations": []
    }
]

System

  • Node.js version: v14.16.1
  • NPM version: v6.14.12
  • Strapi version: v4.0.0-beta.12 && v3.6.8
  • Database: v4 (sqlite3) v3 (MySQL)
  • Operating system: Mac

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions