tags:

views:

626

answers:

1

I read so many post and I found many variations about how to get save to insert vs update but couldn't find something that would work for me.

I am guessing that preSave would be the way to go if preSave() is being executed automaticly by save() if present.

columns:
  email:
    type: string(255)
    unique: true
    email: true

I need save() to check if a filed is set to be unique if so, to check if field data in this case email address is unique. Based on that info decide to insert or update posted fields that have changed.

A: 
    public function preSave($event)
    {
        if (!$this->isUniqueEmail()) {
            $event->skipOperation();
        }
    }

But I suggest you to use validators for this.

Vladimir
This would prevent it from being inserted but rather then skip Operation I like it to update the field.
TaMeR