Preloading child rows 2 levels deep?

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?

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

On 3/9/06, Justin C. [email protected] 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.

Jeremy E. wrote:

On 3/9/06, Justin C. [email protected] 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.

On 3/9/06, Justin C. [email protected] wrote:

And what is the story with EdgeRails?

http://wiki.rubyonrails.com/rails/pages/EdgeRails

Jeremy E. wrote:

On 3/9/06, Justin C. [email protected] 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 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

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?

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 :slight_smile:

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.

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 :slight_smile:

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.

On 3/9/06, Nathan V. [email protected] wrote:

Jeremy E. wrote:

On 3/9/06, Justin C. [email protected] 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. 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 :slight_smile:

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:insilence_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:inrequire__’
from
c:/webdev/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:18:in
require' from ./script/server:3 from -e:3:inload’
from -e:3

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 :slight_smile:

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+with+Edge+Rails
  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.

so its loading 2 child types 2 levels deep, is it possible?

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 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 :smiley: