Related content questions

24 views
Skip to first unread message

Shane

unread,
May 14, 2021, 1:21:28 PMMay 14
to dotCMS User Group
Hello everyone!

I've been looking through the docs and the forum posts to find some answers, but I haven't quite got a definitive answer yet. But this is probably an easy one.

Is it possible to relate more than one content type per relationship field? In my testing it doesn't seem like it, but I wanted to check I wasn't missing anything.

Thanks!
Shane

Falzone, Chris

unread,
May 17, 2021, 7:17:52 AMMay 17
to dot...@googlegroups.com
No I don't think so.  Not sure the use case but most likely just create multiple relationship fields.  You could also probably use a custom field to achieve what you want.

--
http://dotcms.com - Open Source Java Content Management
---
You received this message because you are subscribed to the Google Groups "dotCMS User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dotcms+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dotcms/873d61f8-d7ef-4c5e-9ed5-ee06fb8c5478n%40googlegroups.com.


--

Christopher Falzone

DevOps Engineer

A Q U E N T  /  VITAMIN T

Shane

unread,
May 25, 2021, 4:30:54 PMMay 25
to dotCMS User Group
Thanks Chris.

Thinking out loud...
On the custom field side of things I wonder exactly how I might need to develop a custom field to relate more than one type of content type?
I haven't jumped into custom field creation yet, so it sounds like I need to dive into the documentation.

If anyone has some tips, let me know.
Thanks again!

Falzone, Chris

unread,
May 25, 2021, 4:50:04 PMMay 25
to dot...@googlegroups.com
I'd probably save the data as json in the field.  Like:
{ child1 : identifier-of-child1, child2: identifier-of-child2, ... }

The problem there is that the relationship data is only stored one way.  You can get all of the children if you are looking at the parent, or you can get the parents if you are looking at the children.  But you don't have it reciprocal.  

Might be better to start with .. what problem are you trying to solve?  Maybe there is a better way to design the structures so that it gets you there without this need.  

Shane

unread,
May 25, 2021, 5:09:06 PMMay 25
to dotCMS User Group
Oh thanks for the quick reply Chris!

Ah true, so the solution I am trying to create are kind of two-fold.
One, we have some related products on some pages, and there has become need to relate more types of content than what we had by default. 
Two, I am also working on a new related products widget that allows us to relate tagged content or various content types. The tagged content should be easy enough, but relating specific items from multiple types would be the new thing.

Yeah the ID's of the content is not a bad idea for a basic related field. I don't think there will need to be reciprocal relationships, but it might be wise to attempt and set it up that way for future possibilities.
What are your thoughts with those solutions in mind? I might wind up doing a simple and complex version of these to fit different use cases... still not sure yet.

Falzone, Chris

unread,
May 26, 2021, 9:38:27 AMMay 26
to dot...@googlegroups.com
I would use 2 (or more) relationship fields (one for each type of related content types), pull them all, and then merge the lists in your code.  

Reply all
Reply to author
Forward
0 new messages