Forum: Ruby on Rails Preloading child rows 2 levels deep?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
A161d5ff793b19ba09770e52d727e233?d=identicon&s=25 Justin Copeland (Guest)
on 2006-03-09 10:00
I currently have 3 tables/models: 1) Clients, 2) Charges, and 3)
Court_Dates.
Clients 1..n Charges 1..n Court_Dates

I am trying to find all clients that have a court_date on a certain day:
something along the lines of (@client.charge.court_date.date ==
Date.today).

I have had success preloading child rows using the :include parameter,
but that only works with a parent and a child, or a parent with multiple
children, but not with a parent who has a child that acts as a parent to
another child.

I don't know if that makes any sense, but I would like to preload 2
levels deep. Any thoughts/suggestions greatly appreciated?
Be09addcbb47f2a684fa5c48bac94149?d=identicon&s=25 David Johnson (Guest)
on 2006-03-09 13:50
(Received via mailing list)
Listening ...

On Thu, 2006-03-09 at 10:00 +0100, Justin Copeland wrote:
> I currently have 3 tables/models: 1) Clients, 2) Charges, and 3)
> Court_Dates.
> Clients 1..n Charges 1..n Court_Dates
>
...
58c44a4a506d878f9a112f1d7b7cb87e?d=identicon&s=25 Jeremy Evans (Guest)
on 2006-03-09 19:27
(Received via mailing list)
On 3/9/06, Justin Copeland <copeland.justin@gmail.com> wrote:
> I don't know if that makes any sense, but I would like to preload 2
> levels deep. Any thoughts/suggestions greatly appreciated?

Wait for Rails 1.1, which will include support for what you want, or
use Edge Rails if you must have the feature now.
A161d5ff793b19ba09770e52d727e233?d=identicon&s=25 Justin Copeland (Guest)
on 2006-03-09 22:22
Jeremy Evans wrote:
> On 3/9/06, Justin Copeland <copeland.justin@gmail.com> wrote:
>> I don't know if that makes any sense, but I would like to preload 2
>> levels deep. Any thoughts/suggestions greatly appreciated?
>
> Wait for Rails 1.1, which will include support for what you want, or
> use Edge Rails if you must have the feature now.

well that is not what i wanted to hear. when is rails 1.1 due out, soon
i hope? And what is the story with EdgeRails? I do not know much about
it.
58c44a4a506d878f9a112f1d7b7cb87e?d=identicon&s=25 Jeremy Evans (Guest)
on 2006-03-09 23:44
(Received via mailing list)
On 3/9/06, Justin Copeland <copeland.justin@gmail.com> wrote:
> And what is the story with EdgeRails?

http://wiki.rubyonrails.com/rails/pages/EdgeRails
7fb3901cce24ff7f9bd517ea92c898ae?d=identicon&s=25 Nathan Ventura (pie-social)
on 2006-03-10 04:28
Jeremy Evans wrote:
> On 3/9/06, Justin Copeland <copeland.justin@gmail.com> wrote:
>> I don't know if that makes any sense, but I would like to preload 2
>> levels deep. Any thoughts/suggestions greatly appreciated?
>
> Wait for Rails 1.1, which will include support for what you want, or
> use Edge Rails if you must have the feature now.

I have Edge Rails, how do I do this?
F15fdc7cb2e911b3808837f2be244add?d=identicon&s=25 Adam Denenberg (Guest)
on 2006-03-10 05:51
(Received via mailing list)
i think you want to use the :through paramater..  Not sure how it works
though.  Search the forum and i think you will find some help on it.

adam
A161d5ff793b19ba09770e52d727e233?d=identicon&s=25 Justin Copeland (Guest)
on 2006-03-10 15:08
Jeremy Evans wrote:
>> I currently have 3 tables/models: 1) Clients, 2) Charges, and 3)
>> Court_Dates.
>> Clients 1..n Charges 1..n Court_Dates
>>
>> I am trying to find all clients that have a court_date on a certain day:
>> something along the lines of (@client.charge.court_date.date ==
>> Date.today).
>>
>> I have had success preloading child rows using the :include parameter,
>> but that only works with a parent and a child, or a parent with multiple
>> children, but not with a parent who has a child that acts as a parent to
>> another child.
>> I don't know if that makes any sense, but I would like to preload 2
>> levels deep. Any thoughts/suggestions greatly appreciated?
>
> Wait for Rails 1.1, which will include support for what you want, or
> use Edge Rails if you must have the feature now.

I don't have to do it that way. I'd rather not mess with Edge Rails
right now, hopefully 1.1 hits the streets soon?. Is there another way to
accomplish basically the same thing?
37b7b848b1e3d667174d28d32d04bcee?d=identicon&s=25 Charles M. Gerungan (Guest)
on 2006-03-10 16:59
(Received via mailing list)
On 10-mrt-2006, at 15:08, Justin Copeland wrote:

>> Wait for Rails 1.1, which will include support for what you want, or
>> use Edge Rails if you must have the feature now.
>
> I don't have to do it that way. I'd rather not mess with Edge Rails
> right now, hopefully 1.1 hits the streets soon?. Is there another
> way to
> accomplish basically the same thing?

Messing with edge rails is just:

1. rake freeze_edge
2. sudo gem update rake (if you're not at 0.7 yet)
3. there is no step 3 :)

Then, if you want to get rid of edge rails, just rm -rf RAILS_ROOT/
vendor/rails.

And what you want is just a syntax change of :include away!

--
Regards, Charles.
58c44a4a506d878f9a112f1d7b7cb87e?d=identicon&s=25 Jeremy Evans (Guest)
on 2006-03-10 22:05
(Received via mailing list)
On 3/9/06, Nathan Ventura <nathanlb@shaw.ca> wrote:
> Jeremy Evans wrote:
> > On 3/9/06, Justin Copeland <copeland.justin@gmail.com> wrote:
> >> I don't know if that makes any sense, but I would like to preload 2
> >> levels deep. Any thoughts/suggestions greatly appreciated?
> >
> > Wait for Rails 1.1, which will include support for what you want, or
> > use Edge Rails if you must have the feature now.
>
> I have Edge Rails, how do I do this?

I haven't used the feature, but it supposedly works like this:

  Client.find(:all, :include=>{:charges=>:court_dates})

See http://dev.rubyonrails.org/ticket/3913.
A161d5ff793b19ba09770e52d727e233?d=identicon&s=25 Justin Copeland (Guest)
on 2006-03-11 01:05
Charles M. Gerungan wrote:
> On 10-mrt-2006, at 15:08, Justin Copeland wrote:
>
>>> Wait for Rails 1.1, which will include support for what you want, or
>>> use Edge Rails if you must have the feature now.
>>
>> I don't have to do it that way. I'd rather not mess with Edge Rails
>> right now, hopefully 1.1 hits the streets soon?. Is there another
>> way to
>> accomplish basically the same thing?
>
> Messing with edge rails is just:
>
> 1. rake freeze_edge
> 2. sudo gem update rake (if you're not at 0.7 yet)
> 3. there is no step 3 :)
>
> Then, if you want to get rid of edge rails, just rm -rf RAILS_ROOT/
> vendor/rails.
>
> And what you want is just a syntax change of :include away!
>
> --
> Regards, Charles.

Well when you put it that way... maybe I will mess with it! Thanks for
the help. Everyone on here is so helpful, I really enjoy this community.
A161d5ff793b19ba09770e52d727e233?d=identicon&s=25 Justin Copeland (Guest)
on 2006-03-11 02:17
Justin Copeland wrote:
> Charles M. Gerungan wrote:
>> On 10-mrt-2006, at 15:08, Justin Copeland wrote:
>>
>>>> Wait for Rails 1.1, which will include support for what you want, or
>>>> use Edge Rails if you must have the feature now.
>>>
>>> I don't have to do it that way. I'd rather not mess with Edge Rails
>>> right now, hopefully 1.1 hits the streets soon?. Is there another
>>> way to
>>> accomplish basically the same thing?
>>
>> Messing with edge rails is just:
>>
>> 1. rake freeze_edge
>> 2. sudo gem update rake (if you're not at 0.7 yet)
>> 3. there is no step 3 :)
>>
>> Then, if you want to get rid of edge rails, just rm -rf RAILS_ROOT/
>> vendor/rails.
>>
>> And what you want is just a syntax change of :include away!
>>
>> --
>> Regards, Charles.
>
> Well when you put it that way... maybe I will mess with it! Thanks for
> the help. Everyone on here is so helpful, I really enjoy this community.

switched to EdgeRails and now the webrick server won't start under
win32:

=> Booting WEBrick...
./script/../config/../vendor/rails/activesupport/lib/active_support/core_ext/kernel/agnostics.rb:7:in
``': Exec format error - rake tmp:create (Errno::ENOEXEC)
	from
./script/../config/../vendor/rails/activesupport/lib/active_support/core_ext/kernel/agnostics.rb:7:in
``'
	from
./script/../config/../vendor/rails/railties/lib/commands/server.rb:28
	from
./script/../config/../vendor/rails/railties/lib/commands/server.rb:28:in
`silence_stderr'
	from
./script/../config/../vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:26:in
`silence_stream'
	from
./script/../config/../vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:26:in
`silence_stderr'
	from
./script/../config/../vendor/rails/railties/lib/commands/server.rb:28
	from
c:/webdev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require__'
	from
c:/webdev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
`require'
	from ./script/server:3
	from -e:3:in `load'
	from -e:3
A161d5ff793b19ba09770e52d727e233?d=identicon&s=25 Justin Copeland (Guest)
on 2006-03-11 06:08
Justin Copeland wrote:
> Justin Copeland wrote:
>> Charles M. Gerungan wrote:
>>> On 10-mrt-2006, at 15:08, Justin Copeland wrote:
>>>
>>>>> Wait for Rails 1.1, which will include support for what you want, or
>>>>> use Edge Rails if you must have the feature now.
>>>>
>>>> I don't have to do it that way. I'd rather not mess with Edge Rails
>>>> right now, hopefully 1.1 hits the streets soon?. Is there another
>>>> way to
>>>> accomplish basically the same thing?
>>>
>>> Messing with edge rails is just:
>>>
>>> 1. rake freeze_edge
>>> 2. sudo gem update rake (if you're not at 0.7 yet)
>>> 3. there is no step 3 :)
>>>
>>> Then, if you want to get rid of edge rails, just rm -rf RAILS_ROOT/
>>> vendor/rails.
 >>>
>>> And what you want is just a syntax change of :include away!
>>>
>>> --
>>> Regards, Charles.
>>
>> Well when you put it that way... maybe I will mess with it! Thanks for
>> the help. Everyone on here is so helpful, I really enjoy this community.
>
> switched to EdgeRails and now the webrick server won't start under
> win32:
>
> => Booting WEBrick...
> 
./script/../config/../vendor/rails/activesupport/lib/active_support/core_ext/kernel/agnostics.rb:7:in
> ``': Exec format error - rake tmp:create (Errno::ENOEXEC)
> 	from
> 
./script/../config/../vendor/rails/activesupport/lib/active_support/core_ext/kernel/agnostics.rb:7:in
> ``'
> 	from
> ./script/../config/../vendor/rails/railties/lib/commands/server.rb:28
> 	from
> ./script/../config/../vendor/rails/railties/lib/commands/server.rb:28:in
> `silence_stderr'
> 	from
> 
./script/../config/../vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:26:in
> `silence_stream'
> 	from
> 
./script/../config/../vendor/rails/activesupport/lib/active_support/core_ext/kernel/reporting.rb:26:in
> `silence_stderr'
> 	from
> ./script/../config/../vendor/rails/railties/lib/commands/server.rb:28
> 	from
> c:/webdev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
> `require__'
> 	from
> c:/webdev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
> `require'
> 	from ./script/server:3
> 	from -e:3:in `load'
> 	from -e:3

Nevermind, got it fixed by:
1) Upgrading to Ruby 1.8.4 from 1.8.2
2) Upgrading Engines
http://rails-engines.org/wiki/pages/Using+Engines+...
3) commenting out line 28 of
vendor\rails\railties\lib\commands\server.rb
   #silence_stderr { `rake tmp:create` }

Now:
Client.find(:all, :include => {:charges => :court_dates}, :conditions =>
["date = ?", Date.today]

works like champ!! Just what I needed.
Cd8c9864d88bcafc164d8fdb820cc451?d=identicon&s=25 Chris (Guest)
on 2006-03-11 20:16
Now what if the charges has court_dates and a charge_type? This doesnt
work:

Client.find(:all, :include => {:charges =>
:court_dates,:charges=>:charge_type}, :conditions => ["date = ?",
Date.today]

neither does this :

Client.find(:all, :include => {:charges => {:court_dates,:charge_type}},
:conditions => ["date = ?", Date.today]

Any ideas?
Cd8c9864d88bcafc164d8fdb820cc451?d=identicon&s=25 Chris (Guest)
on 2006-03-11 20:16
so its loading 2 child types 2 levels deep, is it possible?
Dada8059cae36302f90615bea8e60699?d=identicon&s=25 David Greig (Guest)
on 2006-03-23 22:24
Chris wrote:
> Now what if the charges has court_dates and a charge_type? This doesnt
> work:
>
> Client.find(:all, :include => {:charges =>
> :court_dates,:charges=>:charge_type}, :conditions => ["date = ?",
> Date.today]
>
> neither does this :
>
> Client.find(:all, :include => {:charges => {:court_dates,:charge_type}},
> :conditions => ["date = ?", Date.today]
>
> Any ideas?

Not got access to ruby in front of me to test this but I think the
following will achieve what your after:

Client.find(:all, :include => {:charges => [:court_dates,:charge_type]},
:conditions => ["date = ?". Date.today])

Hope this helps you. Assuming i got it right :D
This topic is locked and can not be replied to.