On 7/07/2009, at 12:43 PM, David Ihnen wrote:
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.
Whoops - I was trying to contrive an example without including all the
cruft of my code, which can lead to there kind of errors.
Thanks for your response. It works well for one parent table. What I'm
really hoping to do is avoid writing code like this
my $process = $self->schema->resultset('ETLProcess')->create({
name => $name,
status_id => $self->get_status_id($status_name),
phase_id => $self->get_phase_id($phase_name),
section_id => $self->get_section_id($section_name),
});
_______________________________________________
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/[email protected]