Looking at the cookbook for inflate_result, does the source_name need to be
explicitly set somehow?
I'm a bit confused because it is getting set to one of the new classes, but
the same for all.

Added to Track class:

package MyApp::Result::Track;
...
sub inflate_result {
    my $self = shift;
    my $track = $self->next::method(@_);
    my $class = __PACKAGE__ . $track->position;
    $self->ensure_class_loaded( $class );
    return bless $track, $class;
}

Now:

select * from track where cd = 1;
 id |    name     | position | cd
----+-------------+----------+----
  1 | Track one   |        1 |  1
  2 | Track two   |        2 |  1
  3 | Track three |        3 |  1
(3 rows)

my $cd = $schema->resultset( 'Cd' )->find(1);

for ( $cd->tracks ) {
    printf(
        "position %d, ref=%s source_name=%s\n",
        $_->position,
        ref,
        $_->result_source->source_name,
    );
}

position 1, ref=MyApp::Result::Track1 source_name=Track3
position 2, ref=MyApp::Result::Track2 source_name=Track3
position 3, ref=MyApp::Result::Track3 source_name=Track3

And sorting by -desc => 'position':

position 3, ref=MyApp::Result::Track3 source_name=Track3
position 2, ref=MyApp::Result::Track2 source_name=Track3
position 1, ref=MyApp::Result::Track1 source_name=Track3



$ cat Track?.pm
package MyApp::Result::Track1;
use parent MyApp::Result::Track;
__PACKAGE__->source_name('Track1');
1;
package MyApp::Result::Track2;
use parent MyApp::Result::Track;
__PACKAGE__->source_name('Track2');
1;
package MyApp::Result::Track3;
use parent MyApp::Result::Track;
__PACKAGE__->source_name('Track3');
1;




-- 
Bill Moseley
[email protected]
_______________________________________________
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/[email protected]

Reply via email to