Skip to content

Make massive assignment work with setters in CActiveRecords #1245

Closed
mikehaertl opened this Issue Aug 17, 2012 · 1 comment

2 participants

@mikehaertl

If you have an ActiveRecord with custom setters like this:

<?php
class MyRecord extends CActiveRecord
{
    ...
    public function setTest($value)
    {
        $this->something = $value;
    }
}

then you can't assign test with massive assignment:

<?php
$model = new MyRecord;
$model->setAttributes(array(
    'test' => 'testvalue',
));

because in CActiveRecord::setAttributes() we use property_exists(), which does not detect getters/setters:

<?php
    public function setAttribute($name,$value)
    {
        if(property_exists($this,$name))
            $this->$name=$value;
        else if(isset($this->getMetaData()->columns[$name]))
            $this->_attributes[$name]=$value;
        else
            return false;
        return true;
    }

This is an unneccesary limitation i think. It also works for CFormModel so why not make it work for ActiveRecords, too?

@cebe
Yii Software LLC member
cebe commented May 27, 2013

Closed for reasons described in #1708 .

@cebe cebe closed this May 27, 2013
@cebe cebe was assigned May 27, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.