creatoro/jelly — Issue #94: Can't set add ManyToMany relations on a new Model
Author: ccazette
Created: 2011-10-23 18:47:54+00:00
State: open

... and probably HasMany relations neither looking at the code...

These lines (Core_Model line 353 - don't know why they have been added from the original Jelly) :

// Set an empty value to NULL for deleting relationships
if (($field instanceof Jelly_Field_HasMany OR $field instanceof Jelly_Field_ManyToMany) AND empty($value))
{
$value = NULL;
}

Actually set a the manytomany field to NULL, so the field is reported as 'changed' with a NULL value. If you then try to add a new relation, then this line (942) in the _change() method will trigger an exception as it will run array_merge with a NULL parameter :

if ($add)
{
$changes = array_unique(array_merge($current, $changes));
}