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