[Dbix-class] Shortcut to perform lookups

David Ihnen davidi at norchemlab.com
Tue Jul 7 00:43:40 GMT 2009


Dan Horne wrote:
> Say I have a table called customer  which links to a parent table 
> called status. I wonder if there is a shortcut so that I don't need to 
> figure out the parent id in advance if I know the unique name.
>
> my $status = $self->schema->resultset('Status')->search({status_name 
> => 'new'})->single;
>
> my $customer = $self->schema->resultset->create({
>     name => 'Acme Corp',
>     status_id => $status->id
> })
>

Like this?

$self->schema->resultset('Status')->search({status_name => 
'new'})->single->create_related( 'customer', { name => 'Acme Corp' } );

You didn't put resultset('customer') in your second statement, btw.

David




More information about the DBIx-Class mailing list