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

Comments

Projects
None yet
4 participants
@undsoft
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

This comment has been minimized.

Show comment
Hide comment
@klimov-paul

klimov-paul Aug 10, 2012

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.

Member

klimov-paul commented Aug 10, 2012

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

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Mar 5, 2013

Member

Will not be supported in 1.1.

Member

samdark commented Mar 5, 2013

Will not be supported in 1.1.

@motin

This comment has been minimized.

Show comment
Hide comment

motin commented Feb 6, 2014

@samdark

This comment has been minimized.

Show comment
Hide comment
@samdark

samdark Feb 6, 2014

Member

Yes, it is implemented in Yii2.

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