rsanchez / json

Output ExpressionEngine data in JSON format.
http://devot-ee.com/add-ons/json/
101 stars 234 forks source link

Output for Relationship fields #5

Closed jenschr closed 13 years ago

jenschr commented 13 years ago

I'm having a hard time understanding what the value of a related field contains. Based on my former EE experience, I would expect a Related field to return the entry_id of the related field. Instead, I'm getting a number that has no relation to the data currently in the database. The number increments with each entry, even though referring to the same item in the entry form.

Could this be a bug? How can I translate the number returned (321, 322 and so on) to something useful?

(PS: Thanks for making this great Plugin!!!)

rsanchez commented 13 years ago

The JSON plugin merely returns what's stored in the exp_channel_data. In the case of a relationship field, the data stored in that table is the rel_id for the associated relationship in the exp_relationships table. So, you'd have to do the additional step of translating (via a custom database query) the rel_id into its associated rel_child_id.

Does that make some sense?

jenschr commented 13 years ago

Yup. Thanks!

rsanchez commented 13 years ago

I may opt to change this someday, so that it returns the entry_id of the related entry, so keep an eye on the commit log for that if you ever are updating this plugin to a future version.

jenschr commented 13 years ago

Sweet! Would really simplify things. I'm watching ;-)

rsanchez commented 13 years ago

rel fields now pull the children ids natively. Thanks @sjelfull!