[Catalyst] DBIC custom SQL hack stopped working after upgrading Catalyst

Tobias Kremer tobias.kremer at gmail.com
Fri Aug 6 14:44:03 GMT 2010


Hey folks,

our app is using the following old and rather obscure hack which
injects some custom SQL to perform a UNION.
This works perfectly with the latest DBIC 0.08123 and
Catalyst::Runtime 5.80007. However, after upgrading
to the latest Catalyst::Runtime 5.80025 the app doesn't start anymore
giving this error:

Couldn't load class (MyApp) because:
DBIx::Class::Row::throw_exception(): Can't locate object method
"register_source" via package "MyApp::Schema" at
xxx/MyApp/Schema/User.pm line 357 (see line below).

Any ideas on how to fix this? Please don't tell me to avoid the UNION
altogether because we don't want
to change this ATM. I'm aware that there's
DBIx::Class::ResultSource::View, but this doesn't quite do what
we want, because the view fetching all those friendships between users
would have to return a Schema::User
not Schema::FriendshipView ResultSet. Or am I missunderstanding this
whole virtual view thing? :)

Thanks a lot!

--Tobias


# Mutual friendships
my $source = __PACKAGE__->result_source_instance();
my $source_mutual = $source->new( $source );

# Workaround by mst for the class-based name lookup problems
# when building custom SQL via result_source_instance().
# See: http://www.mail-archive.com/dbix-class@lists.rawmode.org/msg03490.html
@MyApp::Schema::UserView::ISA = ('MyApp::Schema::User');
$source_mutual->result_class( 'MyApp::Schema::UserView' );

$source_mutual->source_name( 'UserMutualFriends' );

my $friendship_sql = qq|SELECT f.id AS friendship_id, u.* FROM users u
INNER JOIN friendships f ON u.id = f.initiator_user_id
WHERE f.receiver_user_id = ?
AND f.date_confirmed IS NOT NULL
UNION
SELECT f.id AS friendship_id, u.* FROM users u
INNER JOIN friendships f ON u.id = f.receiver_user_id
WHERE f.initiator_user_id = ?
AND f.date_confirmed IS NOT NULL|;

$source_mutual->name( \"(${friendship_sql})" );
$source_mutual->add_column( 'friendship_id' );

# Line 357 that breaks latest Catalyst:
MyApp::Schema->register_source( 'MyApp::Schema::MutualFriends' =>
$source_mutual );



More information about the Catalyst mailing list