Re: [CDBI] How do I use deflate?
[email protected] Fri, 1 Jun 2007 17:33:06 -0700 (PDT)
| Newsgroups | gmane.comp.lang.perl.modules.class-dbi |
|---|---|
| Message-ID | <[email protected]> |
> I can update the location_id field for a host just fine like this:
> $host->location_id(1); # or some other location's primary key
>
> I want to be able to update the location_id field for a host like so:
> $host->location_id('SomeLocationName');
here's another approach to consider; a simple wrapper which loses the _id
suffix in the process:
sub location {
my $self = shift;
return $self->location_id() unless @_;
my $name_or_id = shift;
if ($name_or_id =~ /^[0-9]+/) {
$self->location_id( int($name_or_id) );
} else {
my $location = Location->find_or_create({ name => $name_or_id });
$self->location_id( $location->id );
}
}