views:

255

answers:

2

I saw this on a blog today, and I thought, finally! Rails will have something like HQL or Linq. Um, or not. I couldn't find anything about this.

What I really want to know: will I be able to forget what the tables are called and use the object names only? Can I finally forget join syntax? I'd like to do that before I start forgetting everything else (life goals).

A: 

You can read more about it here. I'm not terribly familiar with LINQ, but I believe LINQ is somewhat similar to the query interface used by Django's ORM. At any rate, the gist is that the query interface in Active Record is more like that of Django that it was before. A lot of the older "low-level" query methods are deprecated and will be removed in later versions.

mipadi
I had actually seen that article, but the question is: so? They've changed a lot. Anything good coming out of this?
Yar
Well, if you think a chainable query language is a good thing, then yeah, something good is coming out of this.
mipadi
Sorry, what's the difference between chaining queries and performing queries out of the ActiveRecords returned, as we did before?
Yar
+2  A: 

As far as I understand, this means that you can write your complex queries not as

Object.find(:all, :conditions = > { :limit => 10, :offset => 5 }

but more readable way

Object.all.limit(10).offset(5)
Vestel
Read that too. Why is that good?
Yar
One of the benefits of this is that it doesn't evaluate the expression until you ask for the contents. So that won't execute ANY SQL until you iterate over it. It's going to make caching a lot simpler.
jonnii
Thanks @jonnii, interesting
Yar
Another point is that you can create a variable with Object.find(:all).limit(10) in controller and iterate over pages with assigning a .offset(10) on each page in view only. This make view controller logic simplier
Vestel
Thanks Vestel, that's a nice addition too.
Yar
Why is that good? Apart of other reasons mentioned earlier in comments, it is also more readable and easier to write. Personaly I don't like to pass many parameters as hash - very easly it's getting very ugly.
klew
Object.find(:all… has been old school for a long time now. Nowadays we do Object.all etc.
John Topley