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.
Justin C. (Guest)
on 2006-03-09 11: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?
David J. (Guest)
on 2006-03-09 14:50
(Received via mailing list)
Listening ...

On Thu, 2006-03-09 at 10:00 +0100, Justin C. wrote:
> I currently have 3 tables/models: 1) Clients, 2) Charges, and 3)
> Court_Dates.
> Clients 1..n Charges 1..n Court_Dates
>
...
Jeremy E. (Guest)
on 2006-03-09 20:27
(Received via mailing list)
On 3/9/06, Justin C. <removed_email_address@domain.invalid> 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.
Justin C. (Guest)
on 2006-03-09 23:22
Jeremy E. wrote:
> On 3/9/06, Justin C. <removed_email_address@domain.invalid> 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.
Jeremy E. (Guest)
on 2006-03-10 00:44
(Received via mailing list)
On 3/9/06, Justin C. <removed_email_address@domain.invalid> wrote:
> And what is the story with EdgeRails?

http://wiki.rubyonrails.com/rails/pages/EdgeRails
Nathan V. (Guest)
on 2006-03-10 05:28
Jeremy E. wrote:
> On 3/9/06, Justin C. <removed_email_address@domain.invalid> 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?
Adam D. (Guest)
on 2006-03-10 06: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
Justin C. (Guest)
on 2006-03-10 16:08
Jeremy E. 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?
Charles M. Gerungan (Guest)
on 2006-03-10 17:59
(Received via mailing list)
On 10-mrt-2006, at 15:08, Justin C. 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.
Jeremy E. (Guest)
on 2006-03-10 23:05
(Received via mailing list)
On 3/9/06, Nathan V. <removed_email_address@domain.invalid> wrote:
> Jeremy E. wrote:
> > On 3/9/06, Justin C. <removed_email_address@domain.invalid> 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.
Justin C. (Guest)
on 2006-03-11 02:05
Charles M. Gerungan wrote:
> On 10-mrt-2006, at 15:08, Justin C. 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.
Justin C. (Guest)
on 2006-03-11 03:17
Justin C. wrote:
> Charles M. Gerungan wrote:
>> On 10-mrt-2006, at 15:08, Justin C. 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
Justin C. (Guest)
on 2006-03-11 07:08
Justin C. wrote:
> Justin C. wrote:
>> Charles M. Gerungan wrote:
>>> On 10-mrt-2006, at 15:08, Justin C. 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.
Chris (Guest)
on 2006-03-11 21: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?
Chris (Guest)
on 2006-03-11 21:16
so its loading 2 child types 2 levels deep, is it possible?
David Greig (Guest)
on 2006-03-23 23: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.