I guess I should state more clearly the API goal I'm looking for here: Say there are these: User, Subscriber, Subscription User: belongs_to :subscriber Subscriber: has n, :users and belongs_to :subscription Subscription: has n, :subscribers (has n, :users, :through => :subscribers)
Now say there are these: db1, db2, db3, db_internal The db[1,2,3] databases are actually just shards of the same schema. Where as db_internal is it's own stand-alone database. Now assume we have each of these setup as a repository. Subscription will use the :db_internal repository. The User and Subscriber models will (want to) use :db1, :db2 *and* :db3 such that finder methods will query any/all of these repositories for results. Here's some things I'd like to be able to do (or similar variations of it): Subscription.first.subscriber.users # => all users belonging to the first subscriber found Subscriber.all(:active => true) # => all active subscribers from :db1, :db2 *and* :db3 repositories User.get(1234).subscriber.subscription Anyway, just wanted to make the goal clear. Cross repository relationships (although I'm pretty sure works fine today), and the ability to use multiple repositories for a single [finder] operation. On Jun 21, 7:47 pm, brianmario <[email protected]> wrote: > I'm just getting started with DataMapper, and am loving the API so > far. The one big hurdle I've been trying to get over is figuring out > how to handle records in N databases (with identical schemas, mind > you) from a single Model. > > Basically, if I did something like "User.all" I want that to return > *all* user records across the repositories: [:db1, :db2, :db3, ...]. I > have a temporary hack in place right now which overrides the "all" > class method, and internally loops through said repositories, calling > super in the context of each. It does this in parallel using threads, > and it all works fine until I need to return the grouped results... I > can't return a simple array because the API spec requires it return a > DataMapper::Collection object. I tried reusing a new Collection object > (created in the overridden "all" class method) and calling #load(super > (query)) for each iteration in my loop of repositories. As I half > expected, I got strange results. > > First, am I even making sense? :P > Second, I'd like to know if this is even possible with todays API (I'm > using 0.9.x, though I hear 0.10 has refactored code in this area?). > And if not, where I might start hacking (DataMapper::Collection?) to > add support for this. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
