Deep associations?
oleander opened this issue · 3 comments
I can't find anything about deep associations in the wiki.
I've this for example;
Gig.includes({song: [{artist: :urls}, :urls]})
I know how to include the first association (song), but how about the rest?
class Gig < ActiveRecord::Base
has_many :song
acts_as_api
api_accessible :my_api do |t|
t.add :song
end
end
Hi :)
in fact acts_as_api works extremely well when you need to render deep nested model data.
You can see an example here in the wiki: https://github.com/fabrik42/acts_as_api/wiki/Including-a-child-association
The important part:
If the model Task has also an api template with the same name (in this case :user_with_tasks), this will automatically be taken for rendering!
An example would be:
class Gig < ActiveRecord::Base
has_many :song
acts_as_api
api_accessible :my_api do |t|
t.add :song
end
end
class Song < ActiveRecord::Base
has_one :artist
acts_as_api
api_accessible :my_api do |t|
t.add :artist
end
end
class Artist < ActiveRecord::Base
has_many :urls
acts_as_api
api_accessible :my_api do |t|
t.add :urls
end
end
Maybe this is not clear in the wiki. :(
Do you have any recommendations how we could improve it?
Thanks,
Chris
Sorry for the delayed reply.
I'll give it a try and see if I can come up with something clearer for the wiki.
Thanks.