[Dbix-class] Shortcut to perform lookups
Jason Galea
lists at eightdegrees.com.au
Tue Jul 7 01:02:56 GMT 2009
The docs appear to indicate that you can't do this when the related
foreign row already exists, but it seems to work for me..
my $customer = $self->schema->resultset('customer')->create({
name => 'Acme Corp',
status_id => { name => 'new'},
});
cheers,
J
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
> })
>
> I've had a peruse of the Cookbook, but couldn't see anything
>
> _______________________________________________
> 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/dbix-class@lists.scsys.co.uk
More information about the DBIx-Class
mailing list