Yii Framework Forum: Cactiverecord Limitations - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Cactiverecord Limitations CActiveRecord limitations Rate Topic: -----

#1 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 17 April 2013 - 07:25 AM

the beforeDelete() method is not invoking for

deleteAllByAttributes();
public function deleteAllByAttributes($attributes,$condition='',$params=array())
{
    Yii::trace(get_class($this).'.deleteAllByAttributes()','system.db.ar.CActiveRecord');
    $builder=$this->getCommandBuilder();
    $table=$this->getTableSchema();
    $criteria=$builder->createColumnCriteria($table,$attributes,$condition,$params);
    $command=$builder->createDeleteCommand($table,$criteria);
    return $command->execute();
}

deleteAll();
public function deleteAll($condition='',$params=array())
{
    Yii::trace(get_class($this).'.deleteAll()','system.db.ar.CActiveRecord');
    $builder=$this->getCommandBuilder();
    $criteria=$builder->createCriteria($condition,$params);
    $command=$builder->createDeleteCommand($this->getTableSchema(),$criteria);
    return $command->execute();
}


deleteByPk();

public function deleteByPk($pk,$condition='',$params=array())
{
    Yii::trace(get_class($this).'.deleteByPk()','system.db.ar.CActiveRecord');
    $builder=$this->getCommandBuilder();
    $criteria=$builder->createPkCriteria($this->getTableSchema(),$pk,$condition,$params);
    $command=$builder->createDeleteCommand($this->getTableSchema(),$criteria);
    return $command->execute();
}




its only invoking for delete();

public function delete()
{
    if(!$this->getIsNewRecord())
    {
        Yii::trace(get_class($this).'.delete()','system.db.ar.CActiveRecord');
        if($this->beforeDelete())
        {
            $result=$this->deleteByPk($this->getPrimaryKey())>0;
            $this->afterDelete();
            return $result;
        }
        else
            return false;
    }
    else
        throw new CDbException(Yii::t('yii','The active record cannot be deleted because it is new.'));
}



i need it for all delete methods.
suggestions appreciated . please
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#2 User is offline   seb7 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 03-April 12

Posted 17 April 2013 - 08:01 AM

AfterDelete is for ActiveRecord, not commands.
0

#3 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 17 April 2013 - 08:09 AM

View Postseb7, on 17 April 2013 - 08:01 AM, said:

AfterDelete is for ActiveRecord, not commands.

what?
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#4 User is offline   seb7 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 03-April 12

Posted 17 April 2013 - 08:22 AM

your code uses

$command=$builder->createDeleteCommand($this->getTableSchema(),$criteria);


That's the CDbCommandBuilder - http://www.yiiframew...bCommandBuilder

AfterDelete is a method of CActiveRecord - http://www.yiiframew...erDelete-detail

---

You can instantiate each object (CActiveRecord) then ->delete() it .
0

#5 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 18 April 2013 - 05:57 AM

View Postseb7, on 17 April 2013 - 08:22 AM, said:

your code uses

$command=$builder->createDeleteCommand($this->getTableSchema(),$criteria);


That's the CDbCommandBuilder - http://www.yiiframew...bCommandBuilder

AfterDelete is a method of CActiveRecord - http://www.yiiframew...erDelete-detail

---

You can instantiate each object (CActiveRecord) then ->delete() it .



i know that man..

pls dont miss lead . the code i pasted is from the CActiveRecord.php file . ok.. not my code.


i am saying that the deleteAllByAttributes(); deleteAll(); deleteByPk(); are not going through the beforeDelete().

very simple.

I need beforeDelete() for all delete methods.
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#6 User is offline   seb7 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 49
  • Joined: 03-April 12

Posted 18 April 2013 - 06:36 AM

View PostRajith R, on 18 April 2013 - 05:57 AM, said:

the code i pasted is from the CActiveRecord.php file . ok.. not my code.

Sorry, but how were we supposed to know that it's yii code ?

View PostRajith R, on 18 April 2013 - 05:57 AM, said:

i am saying that the deleteAllByAttributes(); deleteAll(); deleteByPk(); are not going through the beforeDelete().

very simple.


Override yii deleteAll() with your own in your model :
public function deleteAll($condition='',$params=array())
{
    // find all records using the $condition ans $param

    // loop on this records, one by one to trigger ->delete()

    // return true if all deletion were successfull
}


simple.

Do the same for all functions
0

#7 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 18 April 2013 - 06:42 AM

ok thats the proper way.

I am saying that its the limitation that i faced 1st time with yii.

i am saying this because of the beforeFind() will work for all the findxxxxx() methods !!
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

#8 User is offline   softark 

  • Keep It Simple
  • Yii
  • Group: Moderators
  • Posts: 2,085
  • Joined: 16-February 11
  • Location:Japan

Posted 18 April 2013 - 08:45 AM

Hi Rajith,

It's in fact a limitation, but I think it's a reasonable design decision.

It's true that "deleteAll" could be implemented so that "beforeDelete" would be called for every deleted record. But I don't want it.

When I want to use "deleteAll", what I really want is a thin wrapper over the plain sql of "DELETE FROM ... WHERE ...". I don't want Yii to read all the target records into AR objects before deleting them. It would significantly slow down the process.
0

#9 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 19 April 2013 - 01:45 AM

View Postsoftark, on 18 April 2013 - 08:45 AM, said:

Hi Rajith,

It's in fact a limitation, but I think it's a reasonable design decision.

It's true that "deleteAll" could be implemented so that "beforeDelete" would be called for every deleted record. But I don't want it.

When I want to use "deleteAll", what I really want is a thin wrapper over the plain sql of "DELETE FROM ... WHERE ...". I don't want Yii to read all the target records into AR objects before deleting them. It would significantly slow down the process.


Yeah.. i also found that it would slow down the process ,because of read to AR.

Thanks softark :) :)
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
1

#10 User is offline   Rajith R 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 884
  • Joined: 20-April 11
  • Location:India

Posted 19 April 2013 - 02:19 AM

hi softark,

what is the difference between defaultScope() and beforeFind() ?

this is my post

http://www.yiiframew...397#entry201397
Rajith Ramachandran,
Wiwo inc.
| Mobile: 919995504508
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users