Developer Forum »
Why am I not allowed to reuse a relation?
42 posts

Hi,

I just added a new ContentChildrenPropertyClass, which should relate to the exact same content classes as an existing ContentChildrenPropertyClass in the ContentClass. Hence, I used the same relation, but this caused an error:

Class <ClassName> contains two properties: <OldProperty> and <NewProperty>, which are of the same type and point to the same relation <Relation>!

I just wonder, why is this not allowed? Why can't a relation be duplicated to be reused for properties with the same parent/child-setup?

Thank you in advance.

Anna

174 posts

Hi!

If you have two properties pointing to the same relation from the same class, they would only show the same related content. Can you explain your use case a bit, so we can understand what you are trying to do?

 

Vidar

 

42 posts

I just want two different lists in the same class containing different objects, but of the same content classes.

I guess the easiest solution is to just create a separate relation for the new list

174 posts

Yes, I think that is wise.

When you define a relation you basically create a relation lookup table with two main columns: parent_id and child_id. When you're on a parent node, it selects all the child_ids where parent_id is equal to the parent node.

A relation has not concept or understanding of a property. So two properties using the same relation on the same node will always list the same related nodes (if we allowed two properties using the same relation).

 

Vidar

42 posts

All right,

But based on this I see that the naming we have used on relations may not be correct thinking about the relation behavior. Until now, we have named the relation based on the parent class and the child class(es). E.g. Rel<ParentClass><ChildClass>. This naming raises an issue now in the example we've talked about, as the relations have the same parent/child classes but need separate names.

Do you have another recommended naming convention for the relations?

174 posts

Normally, the naming  Rel<ParentClass><ChildClass> works well, but as you mention, when you have a relation between the same class it doesn't work very well. We have the same case internally a few places:

- for the Parent/Children relation used for the tree structure. We don't use the class at all, and called it RelHierarchical. 

- for the ProductCategory class and the ParentCategory and Subcategories properties, we have called the relation RelProductCategorySubCategory.

Many e-commerce sites have a RelatedProducts relation. It is a relation between products. We often call this relation RelProductsRelatedProducts (m:m).

Hopefully some of the examples can give you some ideas for consistent naming of the relations that works well for your use-case.

 

Vidar

  

 

 

42 posts

All right. I will have a look. Thank you. 

Anna

1