I am running into a major problem getting HAS_MANY working with through. I am trying to implement the use of coupons on my site and I have three tables:
coupon
id
coupon_code
expiry
…
coupon_track
coupon_id
user_id
date
user
id
…
I would normally use a MANY_MANY relationship, but in the coupon_track table I want to track additional information such as the date the user used the coupon code, so I am trying to use HAS_MANY with through. Here are my relations:
Coupon model:
public function relations()
{
return array(
'coupon_tracks'=>array(self::HAS_MANY,'CouponTrack','coupon_id'),
'users'=>array(self::HAS_MANY,'User','user_id','through'=>'coupon_tracks'),
);
}
User model:
public function relations()
{
return array(
'coupon_tracks'=>array(self::HAS_MANY,'CouponTrack','user_id'),
'coupons'=>array(self::HAS_MANY,'Coupon','coupon_id','through'=>'coupon_tracks'),
);
}
I also have a CouponTrack model which has no relations defined.
When I try even a simple query like $coupons = Coupon::model()->findAll(); I get the error:
Property "CHasManyRelation.through" is not defined.
I have looked at the explanation in the definitive guide but can’t seem to figure out what I have messed up. Any help would be greatly appreciate. Thanks!