protected static $_belongs_to = array( 'shipping_address' => array( 'model_to' => 'Model_Address', 'key_from' => 'shipping_address_id', ), 'invoice_address' => array( 'model_to' => 'Model_Address', 'key_from' => 'invoice_address_id', ), );
$customer = Model_Customer::forge(array( 'first_name' => Input::post('first_name'), 'last_name' => Input::post('last_name'), )); $customer->address['invoice'] = Model_Address::forge(array( 'address' => Input::post('address'), 'address2' => Input::post('address2'), 'city' => Input::post('city'), 'state' => Input::post('state'), 'zip' => Input::post('zip'), )); $customer->address['shipping'] = Model_Address::forge(array( 'address' => Input::post('shipping_address'), 'address2' => Input::post('shipping_address2'), 'city' => Input::post('shipping_city'), 'state' => Input::post('shipping_state'), 'zip' => Input::post('shipping_zip'), )); $customer->order[] = Model_Order::forge(array( 'total_cost' => $total_cost, )); $customer->save()Customer Model
class Model_Customer extends \Orm\Model { protected static $_properties = array( 'id', 'first_name', 'last_name', ); protected static $_has_many = array('order','address'); }
class Model_Address extends \Orm\Model { protected static $_properties = array( 'id', 'customer_id', 'first_name', 'last_name', 'address', 'address2', 'city', 'state', 'zip', ); protected static $_has_many = array('order'); protected static $_belongs_to = array('customer'); }
class Model_Order extends \Orm\Model { protected static $_properties = array( 'id', 'customer_id', 'invoice_address_id', 'shipping_address_id', 'total_cost', ); protected static $_belongs_to = array( 'customer', 'shipping_address' => array( 'model_to' => 'Model_Address', 'key_from' => 'shipping_address_id', ), 'invoice_address' => array( 'model_to' => 'Model_Address', 'key_from' => 'invoice_address_id', ), ); }
It looks like you're new here. If you want to get involved, click one of these buttons!