Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Save an already existing attribute creates a new one. #5

Open
jmariani opened this issue Aug 2, 2013 · 5 comments
Open

Save an already existing attribute creates a new one. #5

jmariani opened this issue Aug 2, 2013 · 5 comments

Comments

@jmariani
Copy link

jmariani commented Aug 2, 2013

How to reproduce:

$model = Model::model()->findByPk($pk);
$model->setEavAttribute('attribute', 'value');
$model->save();

Now there's two records at the EavAttr table for the same entity and attibute.

Any guidance?

TIA!

@cebe
Copy link
Member

cebe commented Aug 3, 2013

multiple entries per model in eavAttr table is by design. What is your problem?

@jmariani
Copy link
Author

jmariani commented Aug 4, 2013

Multiple entries for the same attribute by design? I don't think so.
The problem is that an existing attribute is not updated, but duplicated.

@cebe
Copy link
Member

cebe commented Aug 4, 2013

Okay, now I got your problem.

@jmariani
Copy link
Author

jmariani commented Aug 5, 2013

Thank you for your attention. There's a "delete" command executed before the insert is done, but executes returning 0 rows.

@jmariani
Copy link
Author

Hi.
Found problem. When you call "getDeleteCommand" and you are using "attributesPrefix", the delete command does not include the prefix in the where.
I fixed like this:

protected function getDeleteCommand($attributes = array()) {
    // JM FIX!
    $criteria = $this->getDeleteEavAttributesCriteria($attributes);
    foreach ($criteria->params as $index => $param) {
        $criteria->params[$index] = $this->attributesPrefix . $param;
    }
    // JM FIX!
    return $this->getOwner()
        ->getCommandBuilder()
        ->createDeleteCommand($this->tableName, $criteria);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants