[Dbix-class] Multi-tennant application/data and dbix-class
Aaron Trevena
aaron.trevena at gmail.com
Thu Jan 11 16:52:28 GMT 2018
On 9 January 2018 at 06:38, Thomas Klausner <domm at cpan.org> wrote:
> As $schema->tenant_id is basically a global value, you really cannot use
> this approach when multiple "threads" try to write to and read from it
> at the same time.
>
>
> Our solution was to extract the value from the env (eg in a
> controller action) and pass it explictly to the model:
>
> # SomeController
>
> sub some_action {
> my ($self, $req) = @_;
>
> my $customer = $req->jwt_claims->{aud};
> my $some_param = $req->param('foo');
>
> $self->some_model->do_something($customer, $some_param);
> }
>
> # SomeModel
>
> sub do_something {
> my ($self, $customer_id, $foo) = @_;
>
> $self->resultset('SomeTable')->search_rs({
> customer => $customer_id,
> ...
> })
> }
>
>
> Yes, this is a bit more work, and arguably a bit "dumber". But I think
> that the obviousness of what's going on in SomeModel->do_somthing is
> worth the effort.
Thanks Domm,
I think we can have a good solution using request
Catalyst::Component::InstancePerContext / ACCEPT_CONTEXT and
DBIx::Class::RestrictWithObject that should achieve this, otherwise
we'll look at the approach you've got here.
Cheers,
A
--
Aaron J Trevena, BSc Hons
http://www.aarontrevena.co.uk
LAMP System Integration, Development and Consulting
More information about the DBIx-Class
mailing list