class Model_Model extends \Orm\Model
{
protected static $_has_many = array('properties');
protected static $_eav = array(
'properties' => array(
'attribute' => 'name',
'value' => 'value')
);
}
$model = Model_Model::find(1);
$model->new_properties = 'value';
$model->old_properties = NULL; // don't delete from DB
unset($model->old_properties); // not working
// Here is break relation (project_id = null),
// but not physically delete
$project = Model_Project::find(1);
unset($project->settings);
$project->save();
// Here is delete settings from DB,
// but re-created it after $project->save()
$project = Model_Project::find(1);
foreach($project->settings as $s)
{
$s->delete();
}
$project->save();
// Hooray, everything as expectedSo, my question is: "Is it normal behavior for Has Many relations"?
$project = Model_Project::find(1);
foreach($project->settings as $s)
{
$s->delete();
}
unset($project->settings);
$project->save();
class Model_Project extends \Orm\Model
{
protected static $_has_many = array(
'settings' => array(
'key_from' => 'id',
'model_to' => 'Model_Settings',
'key_to' => 'project_id',
'cascade_save' => true,
'cascade_delete' => true,
),
);
protected static $_eav = array(
'settings' => array(
'attribute' => 'key',
'value' => 'value',
)
);
}
class Model_Settings extends \Orm\Model
{
protected static $_belongs_to = array(
'project' => array(
'key_from' => 'project_id',
'model_to' => 'Model_Project',
'key_to' => 'id',
'cascade_save' => true,
'cascade_delete' => false,
),
);
}
It looks like you're new here. If you want to get involved, click one of these buttons!