# load My::Schema::Album, My::Schema::Artist and My::OtherSchema::LinerNotes
__PACKAGE__->load_classes(
{
- 'My::Schema' => qw/ Album Artist /,
- 'My::OtherSchema' => qw/ LinerNotes /
+ 'My::Schema' => [qw/ Album Artist /],
+ 'My::OtherSchema' => [qw/ LinerNotes /]
}
);
__PACKAGE__->set_primary_key( qw/ albumid artistid / );
+=begin hide
+
You can define relationships for any of your classes. L<DBIx::Class> will
automatically fill in the correct namespace, so if you want to say
"a My::Schema::Album object belongs to a My::Schema::Artist object" you do not
__PACKAGE__->belongs_to('artist' => 'Artist');
+=end hide
+
That's all you need in terms of setup.
=head2 Usage
and return an instance of C<My::Schema::Album> that represents this
row. Once you have that row, you can access and update columns:
- $album->name('Physical Graffiti');
+ $album->title('Physical Graffiti');
my $title = $album->title; # holds 'Physical Graffiti'
If you prefer, you can use the C<set_column> and C<get_column>
$new_album->delete;
-You can also remove records without or retrieving first. This
-operation takes the same kind of arguments as a search.
+You can also remove records without retrieving them first, by calling
+delete directly on a ResultSet object.
# Delete all of Falco's albums
- $schema->resultset('Album')->delete({ artist => 'Falco' });
+ $schema->resultset('Album')->search({ artist => 'Falco' })->delete;
=head2 Finding your objects
We also provide a handy shortcut for doing a C<LIKE> search:
# Find albums whose artist starts with 'Jimi'
- my $rs = MyApp::DB::Album->search_like({ artist => 'Jimi%' });
+ my $rs = $schema->resultset('Album')->search_like({ artist => 'Jimi%' });
Or you can provide your own handmade C<WHERE> clause, like: