这是用fuelphp中的额外字段创建多对多关系的正确方法吗


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

关于创建还包括额外字段的多对多关系的文档似乎不多(所以这不仅仅是两个模型的ID)。据我所知,中间需要另一个模型,它将具有额外的字段(因为关系本身不支持它)。

这样做对吗?

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');
}

FuelPHP的ORM不支持多对多表中的任何附加列。当然,你可以做一个变通办法:

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