Yii Framework Forum: Getting error with relational active record - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Getting error with relational active record Rate Topic: -----

#1 User is offline   Taylor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 01-June 10

Posted 03 June 2010 - 03:49 PM

I am trying to set up an order - item relationship. I have 3 tables; order, a linking table called order_item and an item table.

here is the relationship defined in the order model class:
'items' => array(self::MANY_MANY, 'Item', 'order_item(order_id, item_id)'),
here is the relationship defined in the item class:
'order_items' => array(self::BELONGS_TO, 'Order_item', 'item_id'),


Here is the code I am running:

$orders = Order::model()->with('items')->findAll();

And here is the error I get

The relation "items" in active record class "order" is specified with an incomplete foreign key. The foreign key must consist of columns referencing both joining tables.

Can someone help me find what I am missing?

Thanks
0

#2 User is offline   Taylor 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 01-June 10

Posted 03 June 2010 - 05:57 PM

Looks like I had an incorrect relation defined for item. By changing it to;
'orders' => array(self::MANY_MANY, 'Order', 'order_item(item_id, order_id)'),

I was able to get it working.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users