[Dbix-class] DBIx::Class::Storage::Replication -- stick to master flag

John Napiorkowski jjn1056 at yahoo.com
Wed Jan 6 15:04:59 GMT 2010




>
>From: Bill Moseley <moseley at hank.org>
>To: DBIx::Class user and developer list <dbix-class at lists.scsys.co.uk>
>Sent: Tue, January 5, 2010 11:49:37 AM
>Subject: Re: [Dbix-class] DBIx::Class::Storage::Replication -- stick to master flag
>
>
>
>
>On Tue, Jan 5, 2010 at 6:22 AM, John Napiorkowski <jjn1056 at yahoo.com> wrote:
>
>>>
>>
>>
>>
>>Take a look at DBIx::Class::Schema::RestrictWithObject since I think that was written to help with these kinds of trouble, might help. --john
>>
>
>Thanks John.  I'm not clear how that might apply in this case.  I need to hook into DBIx::Class::Storage::Replicated to determine when it selects the master vs. the slaves.
>
>I've looked at RestrictWithObject before and I can see at some level how it would be helpful to enforce a criteria on a search, but calling methods on the objects seems cleaner to me (or use search_related) so never looked that closely at it.  Maybe it does more than I thought.
>

There's a few ways to force master read/write mode.  For example, anything inside a transaction will automatically send read traffic to the master.  For me I find that's enough for nearly all the master read use cases.  You can always add a 'flag' as well:


my $row = $resultset->search(undef, {force_pool=>'master'})->find($pk);

That's what I was thinking regarding ::RestrictedWithObject, although might feel like a big hammer to you.  You could
probably also add that to the default resultset attributes of a resultset subclass

http://search.cpan.org/~frew/DBIx-Class-0.08115/lib/DBIx/Class/ResultSource.pm#resultset_attributes

Since you can put it into the result search attributes you could also do this inside a resultset method.  Let me know how it goes.

john


      



More information about the DBIx-Class mailing list