Ok, I have an explanation. We did a release and App::DB::ResultSet::UserRole is a new class. But, we cache User objects in Memcached (as a DBIC row).
And the old code did this: $user->search_related( 'user_role', { ... } ); which then populated $user->{related_resultsets}{user_role} with the (default?) App::DB::Result class instance (and saved it in Memcached). So, when we rolled out the new code it was using cached $user objects so $user->{related_resultsets}{user_role} was the base ResultSet object which didn't have the "my_method" method. So, it may be as simple as delete $user->{related_resultsets} after fetching the $user object from cache. Can't be that expensive to look up the relationships. Or we could be disruptive and blow away the cache at release time. But, it's not a problem that happens very often. I wonder if it makes sense for DBIC to not save related_resultset in objects if there isn't a specific one -- which would have prevented this. Seems like quite an edge-case. On Wed, Jul 15, 2015 at 4:45 PM, Bill Moseley <mose...@hank.org> wrote: > > > On Wed, Jul 15, 2015 at 3:15 PM, Francisco Obispo <franci...@obispo.link> > wrote: > >> The result of >> >> $self->related_resultset( 'user_role' ) >> >> is a App::DB::ResultSet >> > > But it should return an App::DB::ResultSet::UserRole object. "my_method" > is in the App::DB::ResultSet::UserRole class. > > return $self->related_resultset( 'user_role' )->my_method->count > 0; > > > When I printed Dumper $self->{related_resultsets} (in the > related_resultset() method) when it was NOT working I was getting: > > *Note the class:* > > 'user_role' => bless( { > 'pager' => undef, > 'attrs' => { > 'is_depends_on' => 0, > 'cascade_copy' => 0, > 'accessor' => 'multi', > 'alias' => 'me', > 'bind' => > 'ARRAY(0x7fdf9ac59198)', > 'join_type' => 'LEFT', > 'where' => > 'HASH(0x7fdf9ac58fd0)', > 'cascade_delete' => 0 > }, > 'cond' => > $VAR1->{'user_role'}{'attrs'}{'where'}, > '_result_class' => > 'App::DB::Result::UserRole', > 'result_source' => bless( { > '_columns' > => 'HASH(0x7fdf85857f40)', > 'schema' => > $VAR1->{'user_pref'}{'result_source'}{'schema'}, > > '_unique_constraints' => 'HASH(0x7fdf9696ffc8)', > > '_relationships' => 'HASH(0x7fdf8585b0f8)', > > 'result_class' => 'Appi::DB::Result::UserRole', > > 'source_name' => 'UserRole', > > 'resultset_class' => 'App::DB::ResultSet::UserRole', > > '_columns_info_loaded' => 0, > > 'resultset_attributes' => 'HASH(0x7fdf85857a48)', > '_primaries' > => 'ARRAY(0x7fdf93dcb030)', > > '_ordered_columns' => 'ARRAY(0x7fdf858417e8)', > 'name' => > 'user_role' > }, > 'DBIx::Class::ResultSource::Table' ) > }, '*App::DB::ResultSet*' ) > > > > And then when it is working correctly the Dump shows this: > > 'user_role' => bless( { > 'result_source' => bless( { > > 'source_name' => 'UserRole', > 'name' => > 'user_role', > > '_columns_info_loaded' => 0, > '_primaries' > => 'ARRAY(0x4ceaea0)', > 'schema' => > 'App::DB=HASH(0x2c458d0)', > > 'result_class' => 'App::DB::Result::UserRole', > > '_relationships' => 'HASH(0x783f628)', > > 'resultset_attributes' => 'HASH(0x7834010)', > > 'resultset_class' => 'App::DB::ResultSet::UserRole', > > '_ordered_columns' => 'ARRAY(0x7825410)', > '_columns' > => 'HASH(0x7837d20)', > > '_unique_constraints' => 'HASH(0x4d17b40)' > }, > 'DBIx::Class::ResultSource::Table' ), > 'attrs' => { > 'bind' => > 'ARRAY(0x7b1ace0)', > 'cascade_delete' => 0, > 'accessor' => 'multi', > 'cascade_copy' => 0, > 'is_depends_on' => 0, > 'alias' => 'me', > 'where' => > 'HASH(0x7b71fe0)', > 'join_type' => 'LEFT' > }, > 'pager' => undef, > '_result_class' => > 'App::DB::Result::UserRole', > 'cond' => > $VAR1->{'user_role'}{'attrs'}{'where'} > }, '*App::DB::ResultSet::UserRole*' ) > }; > > -- > Bill Moseley > mose...@hank.org > -- Bill Moseley mose...@hank.org
_______________________________________________ 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