On 28/02/13 05:30, Will Bryant wrote:
> The thing that's got worse is having to write different code for
> associations vs. relations. Currently #all will behave exactly the same
> way on both, which is very useful because you can write code on a model
> class that works the same way whether it's working on a global scope or
> just an association.
I don't understand what you mean. Can you give an example of the two
different bits of code you have to write?
> BTW, the per-request caching mechanism is query caching, which is
> different to the loadedness caching that associations do, which is the
> reason to_a is not a consistent replacement for #all, and why I want at
> least a method that always does a query (#query, for example).
Again, I don't understand. Please provide before/after code so I can
respond to a specific use case.
>> <mailto:
will....@gmail.com>> wrote:
>>
>>> Hi Jarrett,
>>>
>>> As per previous emails, the problem is that you can't now force it to
>>> do a query using any particular method. Associations will cache if
>>> you enumerate them and so will not behave in that simple way.
>>>
>>> Yes we have tests and yes it does show that this kind of change
>>> breaks things. That's why I'm complaining.
>>>
>>> Cheers,
>>> Will
>>>
>>>
>>> On 28/02/2013, at 15:16 , Jarrett Meyer <
jarret...@gmail.com
>>> <mailto:
jarret...@gmail.com>> wrote:
>>>
>>>> Most other "enterprise-y" languages (esp. Java+Hibernate,
>>>> .NET+NHibernate, .NET+Entity Framework) reinforce deferred execution
>>>> of queries: the query is not executed until it is enumerated. This
>>>> is now the exact same behavior as those platforms.
>>>>
>>>> Calling .sum() on an association, before you've enumerated, will
>>>> alter the query to perform a SELECT SUM(...). Obviously, this fails
>>>> on anything that doesn't exist in the database. If you want to
>>>> .sum() in memory, you must enumerate the collection first (calling
>>>> .ToArray() in .NET will do this). I don't know if the author of this
>>>> deferred execution has experience with these other ORM's, but the
>>>> behavior is now identical.
>>>>
>>>> Employee.all vs. Employee.all.to_a is not that big of a deal. And
>>>> you should expect breaking changes with a major version number.
>>>> That's why your code is covered by tests, right?
>>>>
>>>> Signed,
>>>> An-ex-.NET-developer-turned-Rubyist
>>>>
>>>> --
>>>> Jarrett Meyer
>>>> Email:
jarret...@gmail.com <mailto:
jarret...@gmail.com>
>>>> Web: JarrettMeyer.com <
http://jarrettmeyer.com/>
>>>> Twitter: @jarrettmeyer <
http://twitter.com/jarrettmeyer>
>>>>
>>>>
>>>> On Wed, Feb 27, 2013 at 6:09 PM, Will Bryant <
will....@gmail.com
>>>> <mailto:
will....@gmail.com>> wrote:
>>>>
>>>> That's better than nothing, but #all returns a relation now,
>>>> which is half the problem (like when you need to sum methods not
>>>> columns, for eg.).
>>>>
>>>>
>>>> On 28/02/2013, at 12:00 , Duncan Beevers
>>>>> <
j...@jonathanleighton.com <mailto:
j...@jonathanleighton.com>> wrote:
>>>>>
>>>>> > #reload will always run the query.
>>>>> >
>>>>> > If I'm misunderstanding the use case please provide some
>>>>> examples.
>>>>>
>>>>> Hmm. But you can't run reload on a scope to get an array -
>>>>> it returns a relation, which as per previous emails doesn't
>>>>> behave the same.
>>>>>
>>>>> So are you saying we should use .reload.to_a everywhere
>>>>> instead of #all?
>>>>>
>>>>> That really seems like a worse API than #all and this is a
>>>>> very common operation. Is it really worth changing #all to
>>>>> be nearly useless and have no direct to do that?
>>>>>
>>>>> Could we at least have a method that does this, say "query"?
>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the
>>>>> Google Groups "Ruby on Rails: Core" group.
>>>>> To unsubscribe from this group and stop receiving emails
>>>>> from it, send an email to
>>>>>
rubyonrails-co...@googlegroups.com
>>>>> <mailto:
rubyonrails-core%2Bunsu...@googlegroups.com>.
>>>>> <mailto:
rubyonra...@googlegroups.com>.
>>>>> <mailto:
rubyonrails-co...@googlegroups.com>.
>>>>> <mailto:
rubyonra...@googlegroups.com>.
>>>> <mailto:
rubyonrails-core%2Bunsu...@googlegroups.com>.
>>>> <mailto:
rubyonra...@googlegroups.com>.
>>>> <mailto:
rubyonrails-co...@googlegroups.com>.
>>>> <mailto:
rubyonra...@googlegroups.com>.
>>> <mailto:
rubyonrails-co...@googlegroups.com>.
>>> <mailto:
rubyonra...@googlegroups.com>.
>> <mailto:
rubyonrails-co...@googlegroups.com>.
>> <mailto:
rubyonra...@googlegroups.com>.