Tricky include question

I’ve been here before and maybe I’m trying to do something that is not
possible. I am trying to include tables that are associated to other
tables in the actual include statement but not to the original table
call. In this case the furnii table.

this is my original query

@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) + “”

now I need to include 2 more tables skintype and skinstyle. these 2
tables are not associated to either furnii or imageassets but have an
association to the skin table, which is associated to furnii through
imageassets.

can I group them in the same query? or do I have to do a separate query
for skintype and skinstyle and then join it at the end?

Sorry for my premature explanation.

(I have simplified my models to reflect the above question)
my models look like this:

class Furni < ActiveRecord::Base
belongs_to :imageasset
end

class Imageasset < ActiveRecord::Base
has_one :skin
end

class Skin < ActiveRecord::Base
belongs_to :imageasset
belongs_to :skinstyle
belongs_to :skintype
end

class Skintype < ActiveRecord::Base
has_one :skin
end

class Skinstyle < ActiveRecord::Base
has_one :skin
end

On Aug 24, 9:52 pm, Sam G. [email protected]
wrote:

+Skin.conditions_by_like(@search) + “”

now I need to include 2 more tables skintype and skinstyle. these 2
tables are not associated to either furnii or imageassets but have an
association to the skin table, which is associated to furnii through
imageassets.

Sure you can, you can nest includes as deep as you want. I’ve got some
examples at

Fred

Frederick C. wrote:

On Aug 24, 9:52�pm, Sam G. [email protected]
wrote:

+Skin.conditions_by_like(@search) + “”

now I need to include 2 more tables skintype and skinstyle. these 2
tables are not associated to either furnii or imageassets but have an
association to the skin table, which is associated to furnii through
imageassets.

Sure you can, you can nest includes as deep as you want. I’ve got some
examples at
Nested includes and joins - Space Vatican

Fred

Thanks for the link. I’m still not sure on how to join the 2 tables in
question.

I tried :include =>[:raider, {:imageasset => {:skintype =>:skin}] but
that is not finding the association
I tried :include =>[:raider, {:imageasset => {:skin =>:skintype}] that
is not working ether.

skin belongs to skintype so I’m not sure how to load it

Sam G. wrote:

I tried :include =>[:raider, {:imageasset => {:skintype =>:skin}] but
that is not finding the association
I tried :include =>[:raider, {:imageasset => {:skin =>:skintype}] that
is not working ether.

skin belongs to skintype so I’m not sure how to load it

Please disregard the question above. Your examples cleared it all up.
Thanks again for your help.