1

I think FuelPHP doesn't support this feature, but I would like to know the best way to do it....

I have 3 SQL tables: users, modules, modules_users. an user has many modules, and a module may have many users (who follow it). In modules_users, there's the actual_state of the module for this user.

modules_users has these fields: - id - user_id - module_id - actual_state - previous_state - updated_at

I need two ORM Models: Model_User and Model_Modules. I'd like to have access of related objects like this:

$actual_state = Model_User::find($id_user)->modules[$id_module]->actual_state; // from the table `modules_users`
$label = Model_User::find($id_user)->modules[$id_module]->label; // from the table `modules`
// and so on... 

How could I do that?

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Allan Stepps
  • 1,047
  • 1
  • 10
  • 23

1 Answers1

1

The best way would be to create an extra model that represents your through table (modules_users) and then you would be able to easily access the extra property in your through table.

Emlyn
  • 852
  • 6
  • 16
  • Yep, that's what I did, I created `Model\ModulesUsers`. The problem is `Model\ModulesUsers` objects are now ordered and « key-ed » by their ID, which I don't care (I need `\Model\Module` to correctly work). I think I gonna have to create a custom method to have the correct result: - I would like an `\Model\Module` object with \Model\Module attributes **AND** `\Model\ModuleUser` attributes, it looks like I need extends to extend `\Model\Module` ? – Allan Stepps Mar 03 '14 at 13:37
  • Fuel does not offer you a way to be able to merge properties from the through table. The only way to do that would be to have the extra module. If you wanted those custom properties included you would have to add the code in manually into your model that does that. It sounds like you might need to assess your design if you are looking to "merge" two models together like that. – Emlyn Mar 03 '14 at 15:11