I came across this post in the forums the other day…
I have two modules created in Module Builder
Subscribers and SubscribersInfo
SubscriberInfo module has “subscriber_id” field.
I need to show all entries with matching subscriber_id from SubscriberInfo table as subpanel of Subscribers.
When I try creating relationship through Module Builder it creates additional table – “subscribers_subscribersinfo_c”.
Is there any way to create one-to-many relationship without additional table?
While we always recommend to use Module Builder for creating relationships, there’s definitely many areas in the product that we don’t and thus build these relationships without the intermediate table in between. There can even be a bit of performance boost without using the middle table, as it’s one less table join needing done when querying records.
Fortunately, this is pretty easy to do, and very similar to the technique used for creating flex relate fields. Let’s look at the code you need to add in a new file custom/Extension/modules/SubscribersInfo/Ext/Vardefs/SubscriberRelate.php…
There are three parts to this file. The first part defines the two fields for the relationship: subscriber_name which is the name field we are referencing from the Subscribers module, and subscriber_id which is the ID of the related subscriber. We next the link field for the relationship between the Subscriber and SubscriberInfo module. Finally, we define the actual relationship itself.
For the sake of completeness, you should also add the link field that references this relationship on the Subscribers module as well in new filec ustom/Extension/modules/Subscribers/Ext/Vardefs/SubscriberInfoRelate.php…
This will enable having a subpanel on the Subscribers DetailView to show all of the SubscriberInfo records.
Finally, do a quick repair and rebuild and you can add this record on any Detail, Edit, or ListView with ease.