Yii Framework Forum: Scopes - Yii Framework Forum

Jump to content

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

Scopes Proposal: a different approach on scopes

#1 User is offline   Rodrigo Coelho 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 664
  • Joined: 05-August 10
  • Location:Rio de Janeiro, Brazil

Posted 10 February 2012 - 06:40 AM

Proposal: a different approach on scopes.

  • DRY: Scopes must be defined only in the "scopes" method or in their own methods (for parameterized ones). In the method "defaultScope", there should be only a reference to a previously declared scope.

  • Resetting: Ability to reset only selected scopes. This improves maintanability. The motivation for this is that you can't specify a scope that disables a default scope*. Having the ability to disable only a selected scope improves maintanability because it is not needed to review/change every query where scopes are reset.


* You can't specify the scopes "active" and "inactive" in the same query, since the resulting query will have something like this: "WHERE active = 1 AND active = 0". Another proposal would be to have something like "binary" or "overridable/grouped" scopes. The developer could specify an id to the scopes and when another scope of the same id is applied, the former scope is overriden by the new scope.
1

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