How do relations really work in Craft 5? #17823
-
|
One thing I still haven't been able to fully get a handle on for Craft 5, is exactly how relations work in comparison to earlier versions. Before Craft 5, relations were stored in the In Craft 5, relations are stored in the content JSON in the AFAICT, the Specifically, I'm currently writing a plugin that is going to interface heavily with relations, and so I'd love to get some clarity on the following questions:
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
We started storing the target element IDs in the That said, the For your use case, are you defining a new element type? Are the relations defined with a custom field that extends |
Beta Was this translation helpful? Give feedback.
We started storing the target element IDs in the
contentJSON in Craft 5.3, to get multi-instance support working for relation fields. They still store values in therelationstable as well, but that table isn’t multi-instance aware, so now each individual field instance also stores its list of target element IDs in thecontentJSON. If thecontentJSON value is set, then the field will use that array when building its field value query. Otherwise it will fall back to joining in therelationstable, like pre-5.3.That said, the
relationstable is not (and won’t be) deprecated, even if it were no longer needed for fallback data, because it’s still referenced when fetching reverse relations.…