Davey
(Davey975)
February 16, 2012, 3:04pm
1
I have a Many to Many table with an extra column (the time that the record has been added):
user_company:
companyId | userId | addTime
In my User model i have:
'memberCompanies' => array(self::MANY_MANY, 'Company', 'user_company(userId, companyId)', 'together' => true)
To get all users linked to a company i use:
<?php
$criteria = new CDbCriteria;
$criteria->with = 'memberCompanies';
$criteria->compare('memberCompanies_memberCompanies.companyId', $this->id);
return new CActiveDataProvider('User', array(
'criteria' => $criteria
)
);
?>
But how can i pass the ‘addTime’ to my gridview?
softark
(Softark)
February 17, 2012, 11:01am
2
Dividing the relation to 2 relations might be a decent solution … it seems somewhat stupid, but I can’t think of a smart solution.
I mean …
From
User - MANY_MANY - Company
To
User - HAS_MANY - UserCompany
UserCompany - BELONGS_TO - Company
dniznick
(Dniznick)
February 17, 2012, 1:40pm
3
Perfect solution.
What you have is really not a many_many relationship if you have extra data columns. You really have two has_many relationships so what softark is proposing is correct.
If you feel like searching there is a good topic at StackOverFlow about this same issue (its not a yii topic but a database design one).