Search code examples
perlmany-to-manydbix-class

dbix::class many-to-many with additional parameters as a JSON


I have a many-to-many relationship in DBIx::Class similar to DBIx:Class many-to-many relationship with additional attribute. Consider that same example on the user_task table with a params column which is type text.

I've been using JSON strings in table columns and doing the inflate/deflate as in

__PACKAGE__->inflate_column(
    'params',
    {   inflate => sub {
            decode_json shift;
        },
        deflate => sub {
            encode_json shift;
        }
    }
);

The result

use Data::Dump qw/dd/; 
my $user_task = $schema->resultset("UserTask")->find({userid=>1,taskid=>1});

dd {$user_task->get_columns}; 

results in

{userid=>1,taskid=>1,role=>"admin",params=>"{}"}

however if

dd {$user_task->get_inflated_columns};

I don't get the expected result. It appears that all of the columns are inflating. From the documentation https://metacpan.org/pod/DBIx::Class::Row#get_inflated_columns, it seems that it should only inflated those columns which have a inflate_column for.

This also appears to be only on many-to-many bridge tables in that if I call get_inflated_columns on non-many-to-many results that the expected occurs.

Question

Is this a bug (or feature)? If it is a feature, is there a reason this doesn't work?

Alternatively, I can build up a result by selectively calling get_inflated_column on only the params column. This seems like it should be unnecessary but perhaps a reasonable work around.


Solution

  • As was stated above, the details were in the many_to_many call, where I had userid as the third argument see the documentation for many_to_many. It should be the name of the accessor.