0

I can't seem to get the ORM "has_many" and "through" case working when I use PSR-0 model names that have more than one word because my model is User_Business_Unit and my table is user_business_unit. For example:

Here is the has_many relationship in my 'User' model:

protected $_has_many = array(
  'business_unit' => array(
     'model' => 'Business_Unit',
     'through' => 'user_business_unit',
     'foreign_key' => 'user_id',
     'far_key' => 'business_unit_id',
);

If I do a

echo $user->has('business_unit', 2);

for example, it will work. But if I do a

$user->add('business_unit', 2);

it fails because it tries to instantiate the model with the 'through' alias "user_business_unit", but the model is "User_Business_Unit".

If I change my 'through' setting to "User_Business_Unit" then the add() case works but the has() case fails because it tries to query the table "User_Business_Unit" but the table is "user_business_unit".

Can someone tell me what I am doing wrong here?

I suppose I could rename my table to be "User_Business_Unit", but that hardly seems like a good solution.

Craig Nakamoto
  • 2,075
  • 2
  • 18
  • 19

0 Answers0