TJ is too short
TJ is too short

Reputation: 873

Saving relationship table data in Joomla Custom Component

I'm developing my first Joomla component and it has been very hard to find proper documentation, so basically I've been checking core components to see how they get things done and try to apply the same method in my component.

However I cannot find how to save related tables. For example, let's say I have three tables:

Users

id,username, other_relevant_columns

Roles

id,rolename, other_relevant_columns

UsersRoles

user_id, role_id other_relevant_columns

When I create a new user, I need to specify which roles the user has and basically I have no idea where to add this code. Do I need to create a custom save method in order to achieve this? Where?

I've been searching this for hours in Google, Joomla forums and I even bought a Joomla book but the custom component they create does not have these type of relationship tables (I started working on this last night, still no sleep and is already 9:41 am!).

PS: Keep in mind that these are only example tables. I'm not actually implementing a user, user roles functionality.

Upvotes: 1

Views: 168

Answers (1)

Markers
Markers

Reputation: 348

The "problem" you're suffering from is that Joomla hasn't really been built with "complex objects" (ie data spread across more than one table) in mind.

I implement this functionality in the model.save method.

mainModel.save() {

       parent.save();

       subModel.save(params if reqd...);

}

Upvotes: 0

Related Questions