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

CActiveRecord cloning #598

Closed
undsoft opened this issue Apr 11, 2012 · 4 comments
Closed

CActiveRecord cloning #598

undsoft opened this issue Apr 11, 2012 · 4 comments

Comments

@undsoft
Copy link
Contributor

undsoft commented Apr 11, 2012

Yii does not support cloning at the moment.

It could be useful.
Consider the following scenario:

$customersShopA = Customer::model()->byMonth()->notDrunk();

$customersShopB = clone $customersShopA;

$customersShopA->byShop('A')->findAll();
$customersShopB->byShop('B')->findAll();

Where ->byMonth() and ->byShop() are scopes defined like this:

public function byShop($shop){
        $this->getDbCriteria()->mergeWith(array(
            'condition'=>'shop = :shop',
            'params'=>array(
                ':shop'=>$shop
            )
        ));

        return $this;
    }

This happens because $this->_c in the model points to the same object.

I know that I can workaround this. Just thought that having this feature in the box would be nice.

@klimov-paul
Copy link
Member

Actually Yii does not support cloning for its classes.

This may cause a lot of troubles, and CActiveRecord is only the top of the iceberg.

"CComponent" class introduces a "behavior" feature, however it does not provide the method "__clone". So if you have attached a behavior to some "CComponent" instance and then has cloned this instance the 2 component objects will share the same behavior object.

Allowing Yii "CComponent" and its child classes to be cloned is a big deal. I am not sure how this can be done properly.

@samdark
Copy link
Member

samdark commented Mar 5, 2013

Will not be supported in 1.1.

@motin
Copy link

motin commented Feb 6, 2014

@samdark
Copy link
Member

samdark commented Feb 6, 2014

Yes, it is implemented in Yii2.

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

4 participants