Is there documentation about how to set a child/parent relationship
between two model objects and update it in the database?
My models look like this:
class Customer extends ActiveRecord
{
var $has_many = array( 'people' => array('order' => 'list_position',
'dependent' => 'destroy'));
...
}
class Person extends ActiveRecord
{
var $belongs_to = 'customer';
var $acts_as = array('list' => array('scope' => 'customer_id',
'column' => 'list_position'));
...
}
So, a customer object has_many Persons.
I found those nice assign() methods, but e.g.
if ($this->my_customer->isValid() && $this->my_person->isValid() ) {
$this->my_person->customer->assign( $this->my_customer );
$this->my_person->save();
$this->my_customer->save();
}
just won't update the table... I had to do it by hand ( $this-
>my_person->customer->id = $this->my_customer->id ).
Now when and how do the foreign key columns get saved?
Reards
TS
Hi,
> So, a customer object has_many Persons.
quick & dirty reply:
$my_custom =& new Customer("put something in here");
$my_custom->person->create("dadadum");
$my_custom->save();
OR
$Ellen =& new Person("...");
$my_costum->person->add($Ellen);
$my_costum->save();
remember: you can use new, create or find to get an Active Record Object!
hm, that wasnt very explicit, anyway
Grüße
Kaste