Or even easier: has n, :comments, :repository => repository(:default) belongs_to :person, :repository => repository(:people)
http://cheat.errtheblog.com/s/datamapper/ -g On Mon, Apr 11, 2011 at 1:33 PM, RipTheJacker <[email protected]> wrote: > wrap the association in the repository block: > > class Person > repository(:default) { > has n, :comments > } > end > > class Comment > repository(:people){ > belongs_to :person > } > end > > On Apr 10, 6:13 am, sivers <[email protected]> wrote: >> What's the best way to do "has n" and "belongs_to" associations >> between two classes that are using two different databases? >> >> My workaround hack, below, works for super-basic get, but it's so >> inelegant, it seems the brighter minds here must have a better >> solution. >> >> Any advice? >> >> ############################# >> DataMapper.setup(:default, 'postgres://localhost/blog') >> DataMapper.setup(:people, 'postgres://localhost/people) >> >> class Person >> include DataMapper::Resource >> def self.default_repository_name >> :people >> end >> property :id, Serial >> # has n, :comments >> def comments >> DataMapper.repository(:default) { Comment.all(:person_id => id) } >> end >> end >> >> class Comment >> include DataMapper::Resource >> property :id, Serial >> property :person_id, Integer, :required => true >> # belongs_to :person >> def person >> DataMapper.repository(:people) { Person.get(person_id) } >> end >> end > > -- > You received this message because you are subscribed to the Google Groups > "DataMapper" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/datamapper?hl=en. > > -- You received this message because you are subscribed to the Google Groups "DataMapper" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/datamapper?hl=en.
