Ryan,
Thanks for the mention of MetaWhere today! I'm really excited about it and I hope it helps make Rails 3 conditions a lot more powerful and flexible. Continuing on your theme, I've also got a post up at http://metautonomo.us/2010/05/11/activerecord-relation-vs-arel/ that your viewers might be interested in which helps to clarify some of the differences between AR and Arel. It also has a few more nifty tricks you can pull with Arel.
Thanks Ryan, it's a real pleasure to heard you each Monday. :)
Sephi-Chan
Thanks Ryan
Rails 3 is very exciting!
I hope to see you at RailsConf 2010, I want to buy you dinner or a least a beer.
Ben
This is perfect! Thanks so much Ryan. I was just exploring the topics you covered today. Can't wait to implement what I learned tomorrow!
How could you list the leaves of a node in an acts_as_nested_set model using arel?
The select statement should be something like this
select * from tree where lft = rgt-1
offtopic: Ryan, could you do something against all the spam comments? Not just those right here, they also are all over the place in older articles, and there are many posted by computers, not just the human ones. This takes at least some fun out of reading the comments.
offtopic: Ryan, could you do something against all the spam comments? Not just those right here, they also are all over the place in older articles, and there are many posted by computers, not just the human ones. This takes at least some fun out of reading the comments.
Thanks for this episode Ryan, awesome work as usual !
I really like the idea behind MetaWhere except the fact that it extends Symbol so I've created a small wrapper around Arel::Attribute (http://github.com/samleb/sexy_scopes).
I hope you guys will find it useful.
Why does .includes not behave like .joins?
Phrase.joins(
:feed_entry_phrase_correlations).merge(
FeedEntryPhraseCorrelation.since(
10.minutes.ago)).all
Generates this sql:
SELECT
`phrases`.*
FROM
`phrases`
INNER JOIN `feed_entry_phrase_correlations` ON `feed_entry_phrase_correlations`.`phrase_id` = `phrases`.`id`
WHERE
(feed_entry_phrase_correlations.created_at > '2010-06-09 16:23:42')
Whereas using .includes:
Phrase.includes(
:feed_entry_phrase_correlations).merge(
FeedEntryPhraseCorrelation.since(
10.minutes.ago)).all
Generates this sql:
SELECT
`phrases`.`id` AS t0_r0,
`phrases`.`phrase` AS t0_r1,
`phrases`.`created_at` AS t0_r2,
`phrases`.`updated_at` AS t0_r3,
`feed_entry_phrase_correlations`.`id` AS t1_r0,
`feed_entry_phrase_correlations`.`feed_entry_id` AS t1_r1,
`feed_entry_phrase_correlations`.`phrase_id` AS t1_r2,
`feed_entry_phrase_correlations`.`count` AS t1_r3,
`feed_entry_phrase_correlations`.`created_at` AS t1_r4,
`feed_entry_phrase_correlations`.`updated_at` AS t1_r5
FROM
`phrases` LEFT OUTER JOIN `feed_entry_phrase_correlations` ON `feed_entry_phrase_correlations`.`phrase_id` = `phrases`.`id` WHERE (feed_entry_phrase_correlations.created_at > '2010-06-09 16:23:42')
Ok, I now understand why it's using LEFT JOINS. (It has to in case the first model does not appear in the second's table).
Here is the real problem as I see it:
When I place a where clause on an included model, AR stops fetching each model in its own query and combines everything into a big LEFT JOIN monstrosity.
While this works, it is very non-performant when several models are included as I get back many many rows that all need to be aggregated by the ORM. This also requires more network IO.
I've created this Gist to demonstrate what's happening:
http://gist.github.com/431943
I'll send a pizza to anyone who can help me with this.
One more note.
The edge documents here:
http://edgeguides.rubyonrails.org/active_record_querying.html
Say:
4.2 Specifying Conditions on Eager Loaded Associations
Even though Active Record lets you specify conditions on the eager loaded associations just like joins, the recommended way is to use joins instead.
---
But they don't say how to eager load associations using joins.
There are a way to concat 2 where clauses with OR operator? Like Post.where("name = 'foo'") | Post.where("name = 'bar'") ?
Wow great information, really helpful to me. http://www.cmonc.com Keep posting just like this. Thanks for precious information.
Took me awhile to read all the comments, but I really love the article. It proved to be very useful to me and I am sure to all the commenters here! It's always nice when you can not only be informed, but also entertained! I'm sure you had fun writing this article. Comfortably, the article is really the sweetest on this precious topic.
love converse all star,love yourself.High quality low price.It's fit for you.
The information you provided was very useful. Because of your help, thank you.
Thanks for such a great post and the review, I am totally impressed! Keep stuff like this coming.
What youre saying is completely true. I know that everybody must say the same thing, but I just think that you put it
in a way that everyone can understand. I also love the images you put in here. They fit so well with what youre trying to say.
Im sure youll reach so many people with what youve got to say.<b><a href=http://www.tygluegun.com>glue stick</a></b> |<b><a href=http://www.tygluegun.com>glue gun</a></b>
|<b><a href=http://www.wanjia-ylm.cn>booster cable</a></b> |<b><a href=http://www.wanjia-ylm.cn>power cord</a></b>
David Heinemeier Hansson..thanks...<a href="http://www.superflatiron.com">chi hair straighteners</a>
Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it. My readers have about the same interets
t's always nice when you can not only be informed, but also entertained! I'm sure you had fun writing this article. Comfortably, the article is really the sweetest on this precious topic.
there are many posted by computers, not just the human ones. This takes at least some fun out of reading the comments.
`feed_entry_phrase_correlations`.`updated_at` AS t1_r5
FROM
`phrases` LEFT OUTER JOIN `feed_entry_phrase_correlations` ON `feed_entry_phrase_correlations`.`phrase_id` = `phrases`.`id` WHERE (feed_entry_phrase_correlations.created_at >
Thanks for sharing your article. I really enjoyed it. I put a link to my site to here so other people can read it.
I know that everybody must say the same thing, but I just think that you put it .






