Hi,
Thanks for great component!
I found small issue with current CAdvancedArBehavior version.
Here:
protected function writeRelation($relation)
{
...
// An array of objects is given
foreach($this->owner->$key as $foreignobject)
{
if(!is_numeric($foreignobject))
{
$foreignobject = $foreignobject->{$foreignobject->$relation['m2mForeignField']};
}
$this->execute($this->makeManyManyInsertCommand($relation, $foreignobject));
}
}
The problem is that {$foreignobject->$relation[‘m2mForeignField’]} is the name of the field inside relation table and not in the foreign table.
For example, we have table posts with id primary key and categories also with id primary key and relation table post_category(category_id, post_id).
Then $foreignobject->{$foreignobject->$relation[‘m2mForeignField’]} is evaluated as $foreingobject->category_id and I have no such field in categories table.
This can be fixed with this change (actually CAdvancedArBehavior v0.2 works this way):
protected function writeRelation($relation)
{
...
// An array of objects is given
foreach($this->owner->$key as $foreignobject)
{
if(!is_numeric($foreignobject))
{
//$foreignobject = $foreignobject->{$foreignobject->$relation['m2mForeignField']};
$foreignobject = $foreignobject->{$foreignobject->tableSchema->primaryKey};
}
$this->execute($this->makeManyManyInsertCommand($relation, $foreignobject));
}
}
Here we use primary key name from foreign table instead of key name from relation table.