You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this gist: https://gist.github.com/seanwalbran/5501979
the query resulting from combining the has-many-through relationship with the named scopes behaves very differently depending on whether the scope is a lamba or not, as of 4.0.0.rc1:
I, [2013-05-02T07:52:37.973373 #55506] INFO -- : with lambda
D, [2013-05-02T07:52:37.975057 #55506] DEBUG -- : (0.1ms) SELECT COUNT(*) FROM "users" INNER JOIN "user_mentions" ON "users"."id" = "user_mentions"."user_id" WHERE "user_mentions"."post_id" = ? AND "users"."admin" = 't' [["post_id", 1]]
I, [2013-05-02T07:52:37.975166 #55506] INFO -- : without lambda
D, [2013-05-02T07:52:37.976599 #55506] DEBUG -- : (0.1ms) SELECT COUNT(*) FROM "users" WHERE "users"."admin" = 't'
Note the complete absence of the join in the second query; up through 4.0.0.beta1, both queries were identical.
While I understand that the migration guide states that "Rails 4.0 requires that scopes use a callable object such as a Proc or lambda", the implementation only communicates that "Using #scope without passing a callable object is deprecated." The above behavior difference is sufficiently broken to be inconsistent with 'deprecation'.
The text was updated successfully, but these errors were encountered:
Above code is executed. However since the scope is not using block type the relation object is already created and that relation object does not make use of scoping.
I can force it by changing the code to
r = @klass.send(method, *args, &block)
r.is_a?(ActiveRecord::Relation) : @klass.current_scope.merge(r) : r
However that is causing two tests to fail.
One potential issue is that I am applying same condition twice if scope is using block format.
Need to find a way to distinguish between the relations that are built lazily vs the relations which are built when class is loaded. I'll look into it more and will update my findings.
In this gist: https://gist.github.com/seanwalbran/5501979
the query resulting from combining the has-many-through relationship with the named scopes behaves very differently depending on whether the scope is a lamba or not, as of 4.0.0.rc1:
Note the complete absence of the join in the second query; up through 4.0.0.beta1, both queries were identical.
While I understand that the migration guide states that "Rails 4.0 requires that scopes use a callable object such as a Proc or lambda", the implementation only communicates that "Using #scope without passing a callable object is deprecated." The above behavior difference is sufficiently broken to be inconsistent with 'deprecation'.
The text was updated successfully, but these errors were encountered: