Hello,
I have an orders and items table setup as one to many.
When I execute the code, the orders info is correct, but the items found is wrong.
I checked the records and have the correct foreign key.
Here is my code.
$order = Orders::model()->findByPk($insert_id);
// I also tried
$order = Orders::model()->with('items')->findByPk($insert_id);
$message = "Order Number: " . $order->id . "<br/><br/>";
foreach($order->items as $item)
{
$message .= "SKU: " . $item->item . "<br/>"; // wrong item
}
Orders.php
'items' => array(self::HAS_MANY, 'Items', 'id'),
Items.php
'orders' => array(self::BELONGS_TO, 'Orders', 'order_id'),
I just want to read the parent and get all items ordered.
Thanks for the help