class Videoinclude DataMapper::Resourceproperty :id, DataMapper::Property::Serialproperty :name, Stringhas n, :play_list_assocshas n, :lists, "PlayList", :through => :play_list_assocs, :via => :play_listbelongs_to :userendclass PlayListinclude DataMapper::Resourceproperty :id, DataMapper::Property::Serialproperty :name, Stringhas n, :play_list_assocshas n, :videos, "Video", :through => :play_list_assocs, :via => :videobelongs_to :userendclass PlayListAssocinclude DataMapper::Resourceproperty :id, DataMapper::Property::Serialproperty :position, Integerbelongs_to :video, :key => truebelongs_to :play_list, :key => trueendclass Userinclude DataMapper::Resourceproperty :id, DataMapper::Property::Serialhas n, :play_listshas n, :videosproperty :name, Stringend
u = User.create :name => 'username'g = Video.create :name => 'video name', :user => ug.lists << PlayList.create(:user => u, :name => 'list name name')
So it seems that the play_list_assoc -> play_list association is only read after the database is used for the first time. On production I have to force this first use in order to avoid this erroneus behaviour.for g in Video.allf = g.play_list_assocs.firstp f.play_list if fendfor g in Video.allf = g.play_list_assocs.firstp f.play_list if fend
The result?
nil
#<PlayList @id=1 @name="list name name">
You should call 'DataMapper.finalize' before using your models but
after requiring them all. This does a basic sanity check, sets up all
the associations and other things that can only be done when all the
models are loaded up.
Regards
Jon
> --
> You received this message because you are subscribed to the Google Groups
> "DataMapper" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/datamapper/-/ARc8RrWPYBcJ.
> To post to this group, send email to datam...@googlegroups.com.
> To unsubscribe from this group, send email to
> datamapper+...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/datamapper?hl=en.
>