Yii Framework Forum: add scopes to deleteAll - Yii Framework Forum

Jump to content

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

add scopes to deleteAll Rate Topic: -----

#1 User is offline   dckurushin 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 392
  • Joined: 16-March 11
  • Location:Israel

Posted 28 October 2011 - 02:02 PM

AR not accept scopes now... but I think it should...

why findAll apply scopes, and deleteAll not?
dafenetly a needed feature
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,317
  • Joined: 12-October 09
  • Location:Croatia

Posted 28 October 2011 - 02:07 PM

There where an issue about that - http://code.google.c...s/detail?id=649
Find more about me.... btw. Do you know your WAN IP?
1

#3 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 711
  • Joined: 02-July 10
  • Location:Central Poland

Posted 31 October 2011 - 11:25 AM

I agree that scopes should be applied also when using update/delete functions.
I use defaultScope frequently to force some filter on data based on user privileges. Such approach allows me to ensure that user won't see any data it is not allowed for him, but when I saw this thread (and issue log) - I realized that such user CAN delete or update ANY record...

I think it is a bug in fact, because developer can still use scopes in code:

User::model()->active()->deleteAll();

and framework should follow this scope, or shoul yell about deleting record when inner criteria object not being empty (at least warning in log) or it can lead to unpredictable behavior...

What is the concept behind this approach and ignoring scopes on update/delete and why Qiang selected "it won't be fixed"?
red
0

#4 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 711
  • Joined: 02-July 10
  • Location:Central Poland

Posted 18 April 2012 - 11:16 AM

If anyone is interested - I did CActiveRecord overloaded class which adds scope support in update/delete functions. There are some limitations: you can in fact use only 'conditions', without relations as they are treated different in update/delete queries and ordering as it is pointless in update/delete) but it allows to keep scope conditions in one place and respects defaultScope for model.
red
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