In recent attempts to build a plugin that assembles a list of all linked records, Iāve found that the property plugin.fields
fails (at least, intermittently) to return all the fields of the current project as documented, and rather returns only the fields of the current model. I believe this is the reason why Datoās own āInverse Relationshipsā plugin is currently not working
hi @lunelson I anonymized your other account, so that the posts are still visible. Watch this topic, so that you will receive updates
Thanks for the tip @fabrizio !!
Hi @lunelson thank you for reporting this issue!
You are right, at the moment the documentation is misleading because it says that plugin.fields
returns all project fields, while it actually returns only cached project fields. That is why if you have only loaded a single record page, it will only return that recordās model fields.
About the Inverse Relationships plugin, I confirm that it is not working. We will soon release a fix, we will let you know
Thanks @Souljuse, Iām glad for the confirmation. The cached project fields fact explains why the inverse relationships plugin intermittently works: itās actually trying to look up information about the link field in the other model (the one that links to the current one), and depending on page load state I guess this information is sometimes present and sometimes not.
However, I must say Iām disappointed that there isnāt a way to get all the projectās fields: I hope youāll reconsider this aspect of the plugin API and having it actually return all the project fields, because use-cases like this one can only be solved with that information. Even the content management API doesnāt seem to provide a way to get all the projectās fields (you apparently have to specify a model), and in any case doesnāt return all the relational data that the plugin API does
@lunelson I completely understand, but we have many projects with +1000 models and +10000 fields: having to return all fields leads to visible performance problems and delays, which can often be avoided with greater specificity. Having that said, weāre going add a method in the plugin SDK to fetch a model fields without having to resort to custom API tokens, AND, if you really want to download EVERY field, you actually can (we simply advise not to):
curl --request GET \
--url 'https://site-api.datocms.com/site?include=item_types%2Citem_types.fields' \
--header 'Accept: application/vnd.api+json' \
--header 'Authorization: Bearer XXX'
I certainly agree that āgreater specificityā is preferable! I just donāt see a way to do the kind of filtering that I want: what I want ultimately, is a list of all the records which link (via a Link
or Links
field) to the current one, listed by record name, but sorted and grouped by model name. I couldnāt see any way around querying the entire list of fields (at least, fields of those types) in the project
Agreed! We have also an undocumented endpoint that does just that, we should move it to public someday and/or add a section in the record sidebar that shows this info
curl --request GET \
--url 'https://site-api.datocms.com/items/:ID/references' \
--header 'Accept: application/vnd.api+json' \
--header 'Authorization: Bearer XXX'
Oh wow, perfect! Yes a feature in the record sidebar would be great. In the meantime Iām going to develop a plugin that does exactly this !
This is my implementation in Svelte https://github.com/lunelson/datocms-plugin-record-references
Hi! The Inverse Relationships plugin should be fixed, now! Try updating to the last version, @lunelson let us know if everything is working as expected
Thanks for the update! Iāll check it out as soon as I can