Home App Docs Blog Github

Can't get reference field data in state

Hi,
I want to get data from reference model data, however instead of that I got in my state:
@type: “@builder.io/core:Reference”
id: “73634b5213e44cd9b30a384260a7d853”
model: “insurance-partners”
Why?
I don’t understand how to get needed data from this ID or @type, please indicate me what to do
Thank you!

@Jediinspace You are trying to reference this data model on a specific page and it is not showing up in the state? If you have a specific page link I can take a look…

I checked on a random page in your space, and was able to add the data model but going to the data tab in the visual editor, and selecting Connect Data from Builder.io
Screen Shot 2021-11-15 at 12.29.29 PM

Within that menu I was able to select Insurance Partners from the menu

You should then have access to all Insurance Partners in the state Object:
Screen Shot 2021-11-15 at 12.34.42 PM

or if you want a specific entry you can select from the Entry section of the connected data

Let me know if that clarifies for you…if you continue to have issues access the data in state please share any specific links and I would be happy to take a look!

Hi @TimG
There is no problem with data connection.
I have problem with getting referenced data in model.
Here the link to page Builder.io: Drag and drop page builder and CMS
Url must be like ‘http://localhost:3000/en-eu/insurance/dental/’ (path is important, you can see the code it is pretty straight forward)
Снимок экрана 2021-11-16 в 10.45.05

Yes I want the specific entry from partners, but I want to define it inside other model as I did.

P.S. Right now I manually fetch this data via the content api, but I find it strange, why then I need to reference the data in the model.

I understand now, thank you for clarifying. Currently, models that reference other models will only include the reference data, not the data of the referenced model itself. Our system is set up to be extremely flexible, so there are many different ways you can use that model reference to then access the necessary data, as you have mentioned calling the content API is one such way.

You could also connect the insurancePartners data on the page, just as you have done with the insuranceCategories, and then filter content to only include the relevant partners for a given URL path. You would probably need to add an insurance-type field, or ID field to the partner models to filter off of, for example. This would reduce any client-side API calls as well as the data would already be available in state.

Hopefully that helps! Please let me know if you have any further questions

@Jediinspace apologies! I spoke too soon, if your app is built in React, we do have a new option available to include references. If you go ahead and add options={{ includeRefs: true }} to the SDKs <BuilderComponent> it should include references to the relevant models, and give you the data that you want.

Try that in your current set up and please let me know if that works or if you have any other issues we can help troubleshoot!