I have a fairly complex domain that I am trying to report on and am
having
difficulty with report_table.
But, my basic question is about the general use of :include.
model_a has many model_b
model_b has many model_c
model_b has many model_d through model_c
When I do:
model_a.report_table(:all, :include => [:model_b])
I get all the columns of these two models. However, when I do
model_a.report_table(:all, :include => [:model_b, :model_c])
I get an error:
/vendor/rails/activerecord/lib/active_record/association_preload.rb:
115
Can someone help me understand this and how includes should be used in
this situation? I'm curious about the need to make sure about the
inclusion of :id column of one model that is used by another,
especially when it is polymorphic through model 'n'.
Halfordian Golfer wrote: > But, my basic question is about the general use of :include.
> model_a has many model_b > model_b has many model_c > model_b has many model_d through model_c
> When I do: > model_a.report_table(:all, :include => [:model_b])
> I get all the columns of these two models. However, when I do > model_a.report_table(:all, :include => [:model_b, :model_c])
Model_c is not a relation on model_a, you want a nested include: :include => {:model_b => {:include => :model_c}}
And if you wanted model_d: :include => {:model_b => {:include => {:model_c => {:include => :model_d}}}}
Don't ask for the model_d and model_c relations from model_b at the same level as it will cause duplicates (see many previous messages on list).
> I get an error: > /vendor/rails/activerecord/lib/active_record/association_preload.rb: > 115
I'm afraid you'd actually have to give the exception message and a few more lines of backtrace. I suspect it was along the lines of "association doesn't exist" though, so never mind if that's the case.
> Can someone help me understand this and how includes should be used in > this situation? I'm curious about the need to make sure about the > inclusion of :id column of one model that is used by another, > especially when it is polymorphic through model 'n'.
This is exactly what I was looking for and points me back in the right
direction.
My question about the id's stems from the use of it in various
examples that I may have been reading too much in to. It was looking
like you'd need to ensure the id column was present if it was to be
used as a foreign key in subsequent includes. Its absence causing the
include to fail. Again, most likely, my bad interpretation of the
examples I was looking at.
I'll poke about thus newly armed and see what shakes loose.
Indebted.
Tim
On Jun 11, 3:16 am, Andrew France <andrew+li...@avito.co.uk> wrote:
> Halfordian Golfer wrote:
> > But, my basic question is about the general use of :include.
> > model_a has many model_b
> > model_b has many model_c
> > model_b has many model_d through model_c
> > When I do:
> > model_a.report_table(:all, :include => [:model_b])
> > I get all the columns of these two models. However, when I do
> > model_a.report_table(:all, :include => [:model_b, :model_c])
> Model_c is not a relation on model_a, you want a nested include:
> :include => {:model_b => {:include => :model_c}}
> And if you wanted model_d:
> :include => {:model_b => {:include => {:model_c => {:include => :model_d}}}}
> Don't ask for the model_d and model_c relations from model_b at the same
> level as it will cause duplicates (see many previous messages on list).
> > I get an error:
> > /vendor/rails/activerecord/lib/active_record/association_preload.rb:
> > 115
> I'm afraid you'd actually have to give the exception message and a few
> more lines of backtrace. I suspect it was along the lines of
> "association doesn't exist" though, so never mind if that's the case.
> > Can someone help me understand this and how includes should be used in
> > this situation? I'm curious about the need to make sure about the
> > inclusion of :id column of one model that is used by another,
> > especially when it is polymorphic through model 'n'.
> This is exactly what I was looking for and points me back in the right
> direction.
> My question about the id's stems from the use of it in various
> examples that I may have been reading too much in to. It was looking
> like you'd need to ensure the id column was present if it was to be
> used as a foreign key in subsequent includes. Its absence causing the
> include to fail. Again, most likely, my bad interpretation of the
> examples I was looking at.
> I'll poke about thus newly armed and see what shakes loose.
> Indebted.
> Tim
> On Jun 11, 3:16 am, Andrew France <andrew+li...@avito.co.uk> wrote:
> > Hi Tim,
> > Halfordian Golfer wrote:
> > > But, my basic question is about the general use of :include.
> > > model_a has many model_b
> > > model_b has many model_c
> > > model_b has many model_d through model_c
> > > When I do:
> > > model_a.report_table(:all, :include => [:model_b])
> > > I get all the columns of these two models. However, when I do
> > > model_a.report_table(:all, :include => [:model_b, :model_c])
> > Model_c is not a relation on model_a, you want a nested include:
> > :include => {:model_b => {:include => :model_c}}
> > And if you wanted model_d:
> > :include => {:model_b => {:include => {:model_c => {:include => :model_d}}}}
> > Don't ask for the model_d and model_c relations from model_b at the same
> > level as it will cause duplicates (see many previous messages on list).
> > > I get an error:
> > > /vendor/rails/activerecord/lib/active_record/association_preload.rb:
> > > 115
> > I'm afraid you'd actually have to give the exception message and a few
> > more lines of backtrace. I suspect it was along the lines of
> > "association doesn't exist" though, so never mind if that's the case.
> > > Can someone help me understand this and how includes should be used in
> > > this situation? I'm curious about the need to make sure about the
> > > inclusion of :id column of one model that is used by another,
> > > especially when it is polymorphic through model 'n'.
> > I don't know what you mean about the id column.
> On Jun 11, 6:50 am, Halfordian Golfer <walke...@gmail.com> wrote:
> > Hi Andrew,
> > This is exactly what I was looking for and points me back in the right
> > direction.
> > My question about the id's stems from the use of it in various
> > examples that I may have been reading too much in to. It was looking
> > like you'd need to ensure the id column was present if it was to be
> > used as a foreign key in subsequent includes. Its absence causing the
> > include to fail. Again, most likely, my bad interpretation of the
> > examples I was looking at.
> > I'll poke about thus newly armed and see what shakes loose.
> > Indebted.
> > Tim
> > On Jun 11, 3:16 am, Andrew France <andrew+li...@avito.co.uk> wrote:
> > > Hi Tim,
> > > Halfordian Golfer wrote:
> > > > But, my basic question is about the general use of :include.
> > > > model_a has many model_b
> > > > model_b has many model_c
> > > > model_b has many model_d through model_c
> > > > When I do:
> > > > model_a.report_table(:all, :include => [:model_b])
> > > > I get all the columns of these two models. However, when I do
> > > > model_a.report_table(:all, :include => [:model_b, :model_c])
> > > Model_c is not a relation on model_a, you want a nested include:
> > > :include => {:model_b => {:include => :model_c}}
> > > And if you wanted model_d:
> > > :include => {:model_b => {:include => {:model_c => {:include => :model_d}}}}
> > > Don't ask for the model_d and model_c relations from model_b at the same
> > > level as it will cause duplicates (see many previous messages on list).
> > > > I get an error:
> > > > /vendor/rails/activerecord/lib/active_record/association_preload.rb:
> > > > 115
> > > I'm afraid you'd actually have to give the exception message and a few
> > > more lines of backtrace. I suspect it was along the lines of
> > > "association doesn't exist" though, so never mind if that's the case.
> > > > Can someone help me understand this and how includes should be used in
> > > > this situation? I'm curious about the need to make sure about the
> > > > inclusion of :id column of one model that is used by another,
> > > > especially when it is polymorphic through model 'n'.
> > > I don't know what you mean about the id column.
> Duh. I see that this was answered already. Very helpful!!!
> Thanks,
> Tim
> On Jun 13, 8:22 am, Halfordian Golfer <walke...@gmail.com> wrote:
> > Just another quick question on this.
> > In the example where:
> > model_a has many model_b through model_c
> > Do you need to include model_c?
> > Thanks,
> > Tim
> > On Jun 11, 6:50 am, Halfordian Golfer <walke...@gmail.com> wrote:
> > > Hi Andrew,
> > > This is exactly what I was looking for and points me back in the right
> > > direction.
> > > My question about the id's stems from the use of it in various
> > > examples that I may have been reading too much in to. It was looking
> > > like you'd need to ensure the id column was present if it was to be
> > > used as a foreign key in subsequent includes. Its absence causing the
> > > include to fail. Again, most likely, my bad interpretation of the
> > > examples I was looking at.
> > > I'll poke about thus newly armed and see what shakes loose.
> > > Indebted.
> > > Tim
> > > On Jun 11, 3:16 am, Andrew France <andrew+li...@avito.co.uk> wrote:
> > > > Hi Tim,
> > > > Halfordian Golfer wrote:
> > > > > But, my basic question is about the general use of :include.
> > > > > model_a has many model_b
> > > > > model_b has many model_c
> > > > > model_b has many model_d through model_c
> > > > > When I do:
> > > > > model_a.report_table(:all, :include => [:model_b])
> > > > > I get all the columns of these two models. However, when I do
> > > > > model_a.report_table(:all, :include => [:model_b, :model_c])
> > > > Model_c is not a relation on model_a, you want a nested include:
> > > > :include => {:model_b => {:include => :model_c}}
> > > > And if you wanted model_d:
> > > > :include => {:model_b => {:include => {:model_c => {:include => :model_d}}}}
> > > > Don't ask for the model_d and model_c relations from model_b at the same
> > > > level as it will cause duplicates (see many previous messages on list).
> > > > > I get an error:
> > > > > /vendor/rails/activerecord/lib/active_record/association_preload.rb:
> > > > > 115
> > > > I'm afraid you'd actually have to give the exception message and a few
> > > > more lines of backtrace. I suspect it was along the lines of
> > > > "association doesn't exist" though, so never mind if that's the case.
> > > > > Can someone help me understand this and how includes should be used in
> > > > > this situation? I'm curious about the need to make sure about the
> > > > > inclusion of :id column of one model that is used by another,
> > > > > especially when it is polymorphic through model 'n'.
> > > > I don't know what you mean about the id column.