Support

Account

Home Forums General Issues Correct way to structure relations?

Solving

Correct way to structure relations?

  • I have several post types and field groups which are related. I am not sure what is the correct way to structure it.

    eg. imagine cars… I have CPT “model” which is related to “model series”, “manufacturer” and some others. (in practice its more fields, but my explanation will show the problem)

    So I created for “model” a field group “model” which has inside a relation to post type “model series” and a relation to “manufacturer”.

    That would be correct I guess…

    But then I created a field group “model series” for the CPT “model series”. This field group has inside also a relation to “manufacturer” (like model already has).

    In fact my post types are related like that.

    Posttype Model: model- model series – manufacturer

    Posttype Model series: model series – manufacturer

    Posttype Manufacturer: manufacturer

    But because I have inside “model series” a relation to “manufacturer” and also in model a relationship to “model series”, will that cause the “model” post type to be bloated because it would have two times a relationship to “manufacturer” (if you consider that model series has also manufacturer)?

    I created this structure so the post types are all independent. So I can easily create own pages for “model series” and manufacturer.

    But maybe is a structure like the following better?

    model – model series

    model series – manufacturer

    manufacturer

    So would the first or the second variant be better?

    Another question I have, is it performance wise bad to incorporate in a single field group a relation several times to the same post type?

    Because I have in field group model pretty nested a repeater field for social media links where I want to save the social media information to that model. But I also added there a repeater with relation to model series, so i can get the social links for modelseries quickly in php. That means in fact I would have included the relation two times.

    Field group: model. (has already relationship to modelseries)
    |
    Facebook groups
    Repeater:1 facebookgroups model Repeater2: Facebookgroups model series (contains
    another relationship to model series)

    I guess I shouldnt do a second inclusion of model series, if I already included model series in model?

    Hope its understandable. I am just figuring out a good practice to structure my data.

  • I would use

    model -> model series (∞ : 1)
    model series -> manufacturer (∞ : 1)

  • Hi John,
    so you mean the variant with less relations. Only have a relation once?

    Can you tell me why? Would it make a difference performance wise?

    If I also want to include in the model series post type all the available models which exist for that series, how would I do that?

    Do I need to use the post2post plugin? There was written the field needs to have the same name on both posttypes? Can you give me an example for this case, I mean how would you name that field. ModelModelseries or something?

  • I would do it that way because a model is one object of model series and a model series is one object of manufacturer.

    It also removes the duplication of data. If you need the manufacturer of a model you can get that information from the model series it is part of.

    Yes, I would use bidirectional relationship fields.

    The plugin you mention is mine.

    Yes, the fields that connect each item would have both in their names, but I would probably use something short and simple. What you would use would depend on how you generally name thing.
    “model_series”
    “series_mfg”

  • Thanks John! Do you think it is better to use post IDs instead of post objects for the relationships performance wise?

    but i read right, bidirectional doesnt work if it is a subfield?

  • It depends on if you will use basic post data or not. When you get the field, if you get posts then the posts will be cached when ACF does get_posts(). if you are not going to use post data then it is more efficient to use IDs. If you use IDs you can always do your own query to get the posts if you need them.

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.