I have 3 classes - Mix, MixClip, and Clip.
class Mix
include DataMapper::Resource
property :id, Serial
# <removed other code for brevity>
has n, :mix_clips
has n, :clips, :through => :mix_clips
end
class MixClip
include DataMapper::Resource
property :id, Serial
property :order, Integer
belongs_to :mix
belongs_to :clip
end
class Clip
include DataMapper::Resource
property :id, Serial
property :title, String
property :description, Text
has n, :mix_clips
has n, :mixes, :through => :mix_clips
end
MixClip joins the Mix/Clip tables and includes an extra property to describe the clip (order). I would like to know if it's possible to have a clip object and be able to reference the current clip in the context it was loaded in.
So let's say I load a Mix and a Clip like so:
mix = Mix.first
clip = mix.clips.first
Is there a way to get the MixClip that is associated with that specific Clip?
clip.mix_clip.order
It was loaded through join between the table, so I would think there would be a way to do it.
I know I can just get all the mix->mix->clips-> and and drill down, but was wondering if I would be able to go back up levels... it would be simpler.
For those wondering, I'm trying to use this because dm-serializer doesn't have full support for nested associations when returning json/xml and I'd like to be able to just define a method that returns the data.
Thanks.