These are the slides to my talk I gave at the June 2008 talk at the Portland Perl Monger's Meeting.
The focus of the talk was on demystifying DBIx::Class, and is followed by the example located at http://our.coldhardcode.com/svn/misc/DBIC-Beer/
46. In SQL:
SELECT ... FROM table_profiles me LEFT JOIN profile_transaction profile_transactions ON
( profile_transactions.profile_id = me.profile_id ) JOIN nasa_transactions transaction ON
( transaction.transaction_id = profile_transactions.transaction_id ) LEFT JOIN
link_trans_pp link_transaction_purchase ON ( link_transaction_purchase.transaction_id =
transaction.transaction_id ) JOIN purchased_products purchase ON ( purchase.purchased_id =
link_transaction_purchase.purchased_id ) JOIN nasa_membership membership ON
( membership.membership_id = purchase.saved_product_id ) JOIN state_lookup state ON
( state.state_lookup_id = me.state ) JOIN country_lookup country ON
( country.country_lookup_id = me.country_id ) WHERE ( membership.expiration_date >= NOW()
AND purchase.saved_object_key = 'membership' )
47. Now:
my $query = $schema->resultset(‘Profile’)->active_members;
$query->count; # How many?
$query->search({ first_name => ‘Bob’ }); # All matching members named Bob
$query->search({ first_name => ‘Bob’ })->count;
while ( my $profile = $query->next ) {
$profile->cars; # Get all of this persons cars
}
# Clean, no ugly SQL