Barelydead / strapi-plugin-populate-deep

A Strapi plugin that makes it easier to populate deep content structures
172 stars 39 forks source link

Bug: Relation ignored if same name as Collection #38

Open tomh4 opened 1 year ago

tomh4 commented 1 year ago

I think the latest addition for the ciruclar references introduces a case, where a relationship is ignored while populating if it is named the same as the collection. E.g: Collection named "Response" --> strapis plural is responses The same collection as a field named "responses" which is not the same collection, just a list of values

--> It gets ignored since version 3.0.0

20x-dz commented 1 year ago

I can confirm this. We have articles that have a relation with departments and external_reviewers , and those fields are not being populated anymore in v3.0.0, we had to rollback to v2.0.0.

old output (reduced for brevity):

{
   "data":[
      {
         "id":468,
         "attributes":{
            "title":"lorem ipsum",
            "intro":"<p id=\"\">lorem</p>",
            "slug":"lorem-ipsum",
            "createdAt":"2023-03-29T20:29:48.000Z",
            "updatedAt":"2023-06-12T14:00:58.608Z",
            "publishedAt":"2023-03-31T12:22:12.000Z",
            "locale":"de",
            "minutesToRead":0,
            "sources":"<ul><li>1. lorem</li></ul>",
            "date":"2023-03-30",
            "article_category":{
               "data":{
                  "id":4,
                  "attributes":{
                     "name":"lorem-category",
                     "description":null,
                     "createdAt":"2023-06-07T12:42:32.592Z",
                     "updatedAt":"2023-07-24T19:47:53.584Z",
                     "publishedAt":"2023-06-07T12:42:33.335Z",
                     "locale":"de",
                     "slug":"lorem-category",
                     "seo":null,
                     "localizations":{
                        "data":[

                        ]
                     }
                  }
               }
            },
            "articles_related":{
               "data":[

               ]
            },
            "departments":{
               "data":[

               ]
            },
            "seo":null,
            "medical_reviewers":{
               "data":[

               ]
            },
            "external_reviewers":{
               "data":[

               ]
            },
            "localizations":{
               "data":[

               ]
            }
         }
      }
   ],
   "meta":{
      "pagination":{
         "page":1,
         "pageSize":25,
         "pageCount":1,
         "total":1
      }
   }
}

new output (reduced for brevity):

{
   "data":[
      {
         "id":1,
         "attributes":{
            "title":"lorem ipsum",
            "intro":"<p id=\"\">lorem</p>",
            "slug":"lorem-ipsum",
            "createdAt":"2023-03-29T20:29:48.000Z",
            "updatedAt":"2023-06-12T14:00:58.608Z",
            "publishedAt":"2023-03-31T12:22:12.000Z",
            "locale":"de",
            "minutesToRead":0,
            "sources":"<ul><li>1. lorem</li></ul>",
            "date":"2023-03-30",
            "article_category":{
               "data":{
                  "id":3,
                  "attributes":{
                     "name":"lorem-category",
                     "description":null,
                     "createdAt":"2023-06-14T15:51:25.971Z",
                     "updatedAt":"2023-07-26T14:32:54.206Z",
                     "publishedAt":"2023-06-14T15:51:28.283Z",
                     "locale":"de",
                     "slug":"lorem-category",
                     "seo":null,
                     "localizations":{
                        "data":[

                        ]
                     }
                  }
               }
            },
            "articles_related":{
               "data":[

               ]
            },
            "seo":null,
            "medical_reviewers":{
               "data":[

               ]
            },
            "localizations":{
               "data":[

               ]
            }
         }
      }
   ],
   "meta":{
      "pagination":{
         "page":1,
         "pageSize":25,
         "pageCount":1,
         "total":1
      }
   }
}
tholden92 commented 1 year ago

I think I have the same problem. Initially I though it was an issue with the depth, but I see that multiple relations are missing when using ?populate=deep but are visible when explicitly telling strapi to populate them by using, for example, ?populate=cities,districts

The collection name in this case are City and District, so it makes sense in terms of your description.

I am running the newest Strapi release.

tholden92 commented 7 months ago

Is this still an issue?

20x-dz commented 3 months ago

Yes. And until recently I didn't bother looking into it as we continued using v2.0.0 just fine. But now it breaks with the latest strapi version (v4.24.5).

I'll look into the proposed fix in https://github.com/Barelydead/strapi-plugin-populate-deep/issues/42#issuecomment-1744516873, as that issue seems to be a duplicate of this one. Wish me luck… 🤞

[edit] Nevermind, we forgot to remove a deleted component from a dynamic zone. staying at v2.0.0 for now. ✌️