[Dbix-class] Multi-tennant application/data and dbix-class
Mark West
mdwestie at gmail.com
Wed Jan 3 22:22:56 GMT 2018
Have you considered RestrictWithObject?
http://search.cpan.org/~arcanez/DBIx-Class-Schema-RestrictWithObject-0.0002/
lib/DBIx/Class/Schema/RestrictWithObject.pm
Mark
-----Original Message-----
From: dbix-class-bounces at lists.scsys.co.uk
[mailto:dbix-class-bounces at lists.scsys.co.uk] On Behalf Of Andrew Beverley
Sent: Wednesday, January 03, 2018 5:08 PM
To: DBIx::Class user and developer list
Subject: Re: [Dbix-class] Multi-tennant application/data and dbix-class
On Wed, 3 Jan 2018 20:37:58 +0000 Aaron Trevena wrote:
> I was wondering if anyone can share any success, tips and problems of
> using dbix-class in a multi-tenant application.
>
> I'm looking at using tenant id in the main tables,
Yes, that's what I do.
> and thinking best approach will be to add logic to a resultset base
> class or role to hook in forcing queries to restrict by tenant id
Yes, same as. I add an accessor in Schema.pm which contains tenant_id.
Each time a request is made to the application, the very first thing I do is
set $schema->tenant_id.
Then, I add a default resultset (also to Schema.pm), which adds this as a
search automatically to all queries, if it exists in the table.
Here's an example:
https://github.com/ctrlo/GADS/blob/master/lib/GADS/Schema.pm
> and any gotchas,
The one gotcha I hit recently was that if you call
$self->result_source->resultset in a Result, then it will not include the
above tenant_id search. I therefore use
$self->result_source->schema->resultset instead.
Andy
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive:
http://www.grokbase.com/group/dbix-class@lists.scsys.co.uk
More information about the DBIx-Class
mailing list