Phalcon model insert with related model assigned to it caused other model to update as well

Unfortunately this is causing the $organization object to update as well with no changed fields. Is there a use case there where the related model needs to be auto-notified? In my case there is a relationship established as many sites to a single organization to in the reverse as well.

I really like being able to set the related model by the alias name to the object as I think that it helps code readability but I don't think that I will be using it. I'd rather not need to check that changes have been made to each model type before updating. I want to have the option to keep snapshots off for some types of models but its looking like I will need to enable them for all models as there seems to be a lot of unexpected behavior that I will need to be checking for with changes.

$organization = Organizations::foundIt();
if (!$organization) {
    throw new \Exception('Organization does not exist', 1);

$site = new Sites();
// Makes me sad :( that this tries to update the Organizations model when inserting the Sites model
// $site->assign([
//     'name'         => $siteName,
//     'description'  => $description,
//     'active'       => Sites::ACTIVE,
//     'organization' => $organization
// ]);

// This works but is a lot uglier to me.  No huge biggie though
    'name'         => $siteName,
    'description'  => $description,
    'active'       => Sites::ACTIVE,
    'organizationsUuid' => $organization->uuid

if (!$site->create()) {
    $message = implode("\n", $site->getMessages());
    throw new \Exception("$message", 1);

I see now that this is a result of using a ACTION_CASCADE on the relation. It sure would be nice to have ACTION_CASCADE_UPDATE_ONLY and ACTION_CASCADE_CREATE_ONLY or something to that effect.

Now that I think about it I don't think that inserting the new Sites model should cause the Organizations model to be updated. It doesn't make any sense since its more like a bubble up than a cascade. If this bubble up behavior were wanted then it should be set on the relation added to the Sites model.

Its weird right?


set ur organization model


in intialize