[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-07 Thread Marnen Laibow-Koser
Michael Schuerig wrote: > On Tuesday 07 September 2010, Marnen Laibow-Koser wrote: >> Michael Schuerig wrote: > >> TDD. :) > Then don't complain if the reaction indicates a failure. I wasn't the one complaining, was I? [...] >> I may have something else for you. I believe I am close, at any >>

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-07 Thread Michael Schuerig
On Tuesday 07 September 2010, Marnen Laibow-Koser wrote: > Michael Schuerig wrote: > I am still considering a better solution for your problem, though > I'll admit that the spirit in which my attempts have so far been > received is not exactly encouraging me to spend much more time on > the issue.

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-07 Thread Marnen Laibow-Koser
Michael Schuerig wrote: > On Friday 03 September 2010, Marnen Laibow-Koser wrote: >> Marnen Laibow-Koser wrote: > >> Well, you learn something new every day! I found the Ambiguous >> Groups article on the Web and found that the behavior I thought was >> standard -- returning the first value in th

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-04 Thread Michael Schuerig
On Saturday 04 September 2010, Colin Law wrote: > On 4 September 2010 09:14, Michael Schuerig wrote: > > On Friday 03 September 2010, Marnen Laibow-Koser wrote: > >> Marnen Laibow-Koser wrote: > >> > >> Well, you learn something new every day! I found the Ambiguous > >> Groups article on the We

Re: [Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-04 Thread Colin Law
On 4 September 2010 09:14, Michael Schuerig wrote: > On Friday 03 September 2010, Marnen Laibow-Koser wrote: >> Marnen Laibow-Koser wrote: > >> Well, you learn something new every day!  I found the Ambiguous >> Groups article on the Web and found that the behavior I thought was >> standard -- retu

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-04 Thread Michael Schuerig
On Friday 03 September 2010, Marnen Laibow-Koser wrote: > Marnen Laibow-Koser wrote: > Well, you learn something new every day! I found the Ambiguous > Groups article on the Web and found that the behavior I thought was > standard -- returning the first value in the case of multiple values > -- i

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-03 Thread Marnen Laibow-Koser
Marnen Laibow-Koser wrote: > [...] >>> [outer SELECT and JOIN as above] >>> ORDER BY article.id, version.created_at desc >>> GROUP BY article.id >>> [further JOINs may be necessary in some DBs, but the principle holds] >> >> How does this ensure that I get the latest version? > > Sorry, I meant

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-03 Thread Marnen Laibow-Koser
Michael Schuerig wrote: > On Friday 03 September 2010, Marnen Laibow-Koser wrote: >> Then I'm not sure why :joins won't do the trick. > Because :joins, doing a simple inner join on articles and versions, > creates a relation with a row for each version. I want one row, made up > from an article wit

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-03 Thread Michael Schuerig
On Friday 03 September 2010, Marnen Laibow-Koser wrote: > Michael Schuerig wrote: > > On Friday 03 September 2010, Marnen Laibow-Koser wrote: > >> On further reflection, I don't know why you would need an outer > >> join unless not every Article has a Version associated. Is that > >> the case? > >

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-02 Thread Marnen Laibow-Koser
Michael Schuerig wrote: > On Friday 03 September 2010, Marnen Laibow-Koser wrote: >> >> On further reflection, I don't know why you would need an outer join >> unless not every Article has a Version associated. Is that the case? > > I need an *inner* join with the latest of several versions, pos

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-02 Thread Michael Schuerig
On Friday 03 September 2010, Marnen Laibow-Koser wrote: > I had a couple more ideas just after I posted. > > Marnen Laibow-Koser wrote: > > Michael Schuerig wrote: > [...] > > >> :joins with a symbol does an inner join. > > > > So use an SQL fragment if you need an outer join (which, on > > refl

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-02 Thread Marnen Laibow-Koser
I had a couple more ideas just after I posted. Marnen Laibow-Koser wrote: > Michael Schuerig wrote: [...] >> :joins with a symbol does an inner join. > > So use an SQL fragment if you need an outer join (which, on reflection, > I suppose you do). On further reflection, I don't know why you wou

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-02 Thread Marnen Laibow-Koser
Michael Schuerig wrote: > On Friday 03 September 2010, Marnen Laibow-Koser wrote: >> > end >> >[...] >> model, all your Article data fields are really in the Version object. >> That's cumbersome, as you're finding out. > > The data model expresses what I need. Maybe not. If you're finding it

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-02 Thread Michael Schuerig
On Friday 03 September 2010, Marnen Laibow-Koser wrote: > Michael Schuerig wrote: > > Firstly, I've asked a similar question before[*]. I didn't get any > > answers back then, maybe now I have better luck > > > > Let's say I have models like this > > > > class Article < ActiveRecord::Base > >

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-02 Thread Michael Schuerig
On Friday 03 September 2010, Michael Pavling wrote: > On 2 September 2010 22:49, Michael Schuerig wrote: > > Firstly, I've asked a similar question before[*]. I didn't get any > > answers back then, maybe now I have better luck > > It's hard to answer your post, as your only question is in the >

[Rails] Re: Objects with versions: how to avoid 1 + n queries?

2010-09-02 Thread Marnen Laibow-Koser
Michael Schuerig wrote: > Firstly, I've asked a similar question before[*]. I didn't get any > answers back then, maybe now I have better luck > > Let's say I have models like this > > > class Article < ActiveRecord::Base > has_many :versions > end > > class Version < ActiveRecord::Ba