Tesla
Tesla

Reputation: 813

Is this the right way to create a many-to-many relationship with extra fields in fuelphp

There doesnt seem to be much documentation on creating a many-to-many relationship that also includes extra fields (so its not just the IDs of the two models). As far as I understand there needs to be another Model inbetween which will have the additional fields (as the relationship itself doesnt support it).

Is this the right way to do it?

class Model_Ab
{
  protected static $_belongs_to = array('a', 'b');

  //this has the additional fields
}

class Model_A
{
  protected static $_has_many = array('ab');
}

class Model_B
{
  protected static $_has_many = array('ab');
}

Upvotes: 1

Views: 235

Answers (1)

Peter
Peter

Reputation: 1798

FuelPHP's ORM doesn't support any additional columns in the many to many table. Off course you can make a workaround:

modelA -> has_one <=> has_many model_through -> has_many <=> has_one modelB

Upvotes: 2

Related Questions