Hi Brian,

> 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.

This is a pretty interesting use case, that I must admit I've never
considered before.  I actually don't think it'd be too hard to do,
although it will require a bit of patching until the API needed is
more clear.

How I'd approach this is write a subclass of DataMapper::Repository,
and I'd make it so the read() method executes the same query against
each of the repos, and concats the results into a single Array.  You
could even use Query#filter_records to match/sort/limit the results if
necessary.  Return the array from read(), and it'll be turned into a
Collection object, which you can use as normal.

The nice thing is that updating a single Resource in the Collection
should propagate back to the correct shard.  The only tricky part
might be that if you do any bulk operations on the collection (like
Collection#update! or Collection#destroy!) you might have to have your
Repository object handle propagating the update() and delete() calls
to each shard, much like you did with read().

I was thinking something along the lines of:

  # get the first active subscriber with a subscription
  subscriber = Subscription.all.subscribers(:active => true).first

  users = CustomRepository.new(:composite, [ :db1, :db2, :db3 ]).scope
do
    # should execute with the repository, assuming the relationship is
not absolute
    subscriber.users
  end

Granted this is a bit ugly, and we can work out a better API for this
over time, but I'd like to make sure the specific strategy works as-is
before modifying the API to make it cleaner.

Dan
(dkubb)

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to