Getting error with relational active record

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?


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.