Nested include

I’m trying to access data from the skins table through a nested include
with no luck. The association is all through imageasset but I do not
know how to figure it out. Any help is highly appreciated.

######the controller code#######
@furnii_from_furnii = Furni.find :all, :include => [{:raider =>
:imageasset}, :skin ] , :conditions =>
“”+Furni.conditions_by_like(@search)+" OR "
+Raider.conditions_by_like(@search) + “OR”
+Skin.conditions_by_like(@search) + “”

#######I have 4 models set up this way (did only include the necessary
code )#######
class Furni < ActiveRecord::Base
belongs_to :imageasset
belongs_to :raider, :foreign_key => “original_raider_id”
end
class Raider < ActiveRecord::Base
belongs_to :imageasset
end
class Skin < ActiveRecord::Base
belongs_to :imageasset
end

class Imageasset

nothing

end

On Aug 6, 10:35 pm, Sam G. [email protected]
wrote:

I’m trying to access data from the skins table through a nested include
with no luck. The association is all through imageasset but I do not
know how to figure it out. Any help is highly appreciated.

######the controller code#######
@furnii_from_furnii = Furni.find :all, :include => [{:raider =>
:imageasset}, :skin ]

This won’t work unless Furni has an association called imageasset,
which it doesn’t. If you want Activerecord to go through image asset
you’re going to need to either write

:include => [{:raider => :imageasset}, {:imageasset => :skin}]

or

:include => {:raider => {:imageasset => :skin}}

Either way you have to have a skin (or skins, in which case
replace :skin by :skins in the above examples) association on
imageasset.

Fred

Fred,

Tried both your options and I’m still getting the error “Association
named ‘skin’ was not found; perhaps you misspelled it?”

furni has the association imageasset as belongs_to :imageasset. I’m not
sure that changes anything

This won’t work unless Furni has an association called imageasset,
which it doesn’t. If you want Activerecord to go through image asset
you’re going to need to either write

:include => [{:raider => :imageasset}, {:imageasset => :skin}]

or

:include => {:raider => {:imageasset => :skin}}

Either way you have to have a skin (or skins, in which case
replace :skin by :skins in the above examples) association on
imageasset.

Fred

I am Trying to get the data in the skins table. the Association between
furni, raider and skin is through imageasset id. Hope I make sense.

Sam G. wrote:

Fred,

Tried both your options and I’m still getting the error “Association
named ‘skin’ was not found; perhaps you misspelled it?”

furni has the association imageasset as belongs_to :imageasset. I’m not
sure that changes anything

This won’t work unless Furni has an association called imageasset,
which it doesn’t. If you want Activerecord to go through image asset
you’re going to need to either write

:include => [{:raider => :imageasset}, {:imageasset => :skin}]

or

:include => {:raider => {:imageasset => :skin}}

Either way you have to have a skin (or skins, in which case
replace :skin by :skins in the above examples) association on
imageasset.

Fred

On Aug 7, 3:18 am, Sam G. [email protected] wrote:

I am Trying to get the data in the skins table. the Association between
furni, raider and skin is through imageasset id. Hope I make sense.

When I said

This won’t work unless Furni has an association called imageasset,
which it doesn’t
I should of couse have said that ImageAsset should have a skin (or
possibly a skins association). You won’t be getting anywhere without
one.

Fred

So in other words you mean that the imageasset model should have a
has_many :skin or should the association be in the imageasset table with
a skin id?

Frederick C. wrote:

On Aug 7, 3:18�am, Sam G. [email protected] wrote:

I am Trying to get the data in the skins table. the Association between
furni, raider and skin is through imageasset id. Hope I make sense.

When I said

This won’t work unless Furni has an association called imageasset,
which it doesn’t
I should of couse have said that ImageAsset should have a skin (or
possibly a skins association). You won’t be getting anywhere without
one.

Fred

Got it.

this works to by the way :include =>[:raider, {:imageasset => :skin} ]

Frederick C. wrote:

On Aug 7, 3:35�am, Sam G. [email protected] wrote:

So in other words you mean that the imageasset model should have a
has_many :skin or should the association be in the imageasset table with
a skin id?

Either a has_many or a has_one. you need to tell activerecord how to
find a skin from an imageasset (it isn’t enough to just say that
imageasset belongs_to :skin, rails won’t guess the association in the
other direction).

Fred

On Aug 7, 3:35 am, Sam G. [email protected] wrote:

So in other words you mean that the imageasset model should have a
has_many :skin or should the association be in the imageasset table with
a skin id?

Either a has_many or a has_one. you need to tell activerecord how to
find a skin from an imageasset (it isn’t enough to just say that
imageasset belongs_to :skin, rails won’t guess the association in the
other direction).

Fred

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs