[CDBI] How do I use deflate?

mreece at vinq.com mreece at vinq.com
Sat Jun 2 01:33:06 BST 2007


> 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 );
    }
  }





More information about the ClassDBI mailing list