[Dbix-class] question about InflateColumn::DateTime

John Napiorkowski jjn1056 at yahoo.com
Tue Nov 7 19:34:59 GMT 2006


--- John Napiorkowski <jjn1056 at yahoo.com> wrote:

> 
> 
> --- Jess Robinson
> <castaway at desert-island.demon.co.uk>
> wrote:
> 
> > 
> > 
> > On Tue, 7 Nov 2006, John Napiorkowski wrote:
> > 
> > > Hi,
> > >
> > > I've been using InflateColumn::DateTime for a
> few
> > > weeks now for my reports and it's worked very
> > well.
> > > However I have run into the following trouble;
> if
> > I
> > > try to change the datetime object value using
> one
> > of
> > > the setter methods it seems like DBIx doesn't
> > notice.
> > >
> > > Here's an example:  Assume I have a column in a
> > > resultset called 'date_of_birth'
> > >
> > > my $birth_month =
> > $c->resultrow->date_of_birth->month;
> > >
> > > Okay, $birth_month is properly set and I can see
> > that
> > > in the output.  But if I try:
> > >
> > > $c->resultrow->date_of_birth->set_month([new
> > month]);
> > >
> > > and then:
> > >
> > > $c->resultrow->insert_or_update
> > >
> > > The change doesn't get applied.  If I change
> other
> > > columns in this row it works fine.  However when
> I
> > > inspect the $resultrow->is_changed and the
> > > $resultrow->has_dirty_columns I don't see the
> > > 'date_of_birth' column marked as altered.  I
> will
> > see
> > > other columns that I changed.
> > >
> > > I'd like to figure out how to many this work,
> > since I
> > > expect it could also be the case for other
> > inflated
> > > objects that I might have, like a text field
> that
> > gets
> > > inflated to an HTML object, for example.
> > >
> > > Has anyone else run into this and if so what was
> > the
> > > solution you found?
> > >
> > 
> > Hi John,
> > 
> > Whats happening is that
> > 
> > $c->resultrow->date_of_birth->set_month([new
> month])
> > 
> > is creating an unnamed DateTime object, setting
> the
> > new month on it, then 
> > throwing it away. I'm afraid it's not magic enough
> > to grasp what you 
> > wanted to do with that syntax.. You'll need to do
> > something like:
> > 
> > my $dob = $c->resultrow->date_of_birth;
> > $dob->set_month([new month]);
> > $c->resultrow->date_of_birth($dob);
> > $c->resultrow->update;
> > 
> > 
> > Jess
> 
> I was afraid someone would confirm that form me.  I
> got the impression that was happening when I started
> doing Dumper(c$->resultset->set_month(..)) and saw
> the
> DateTime object.
> 
> This is really too bad for me, I had this nice html
> form system where I could name my form fields with
> dots joining accessors to related columns and it
> just
> did what I wanted.  But it looks like I will need a
> better method for handling dates.  Well, there are
> probably a few hundred examples floating around :)
> 
> Still, I wonder if this is something we'd like made
> magical?  I mean one of the great things about DBIx
> (among many) is how easy it is to in/deflate columns
> to objects.  But since there is no particular
> standard
> for how an object alerts that it's been altered in
> some way there is not much we can do.  
> 
> --john

If anyone else runs into this trouble and finds this
thread while searching for a workaround I just made a
bunch of dumb accessors like this:

sub dob_year
{
  my ($self, $value) = @_;
	
  if( defined $value)
  {
     my $dateob = $self->date_of_birth;
		
     $dateob->set_year($value);
     $self->date_of_birth($dateob);
  }
	
  return $self->date_of_birth->year();
}

Now that I'm looking at it, might make a nice
component to automatically create for you, something
like?

__PACKAGE__->create_DateTime_accessors(qw/col1 col2/);
__PACKAGE__->create_DateTime_mutators(qw/col1 col2/);

What do you think?

--john



 
____________________________________________________________________________________
Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail.
http://new.mail.yahoo.com



More information about the Dbix-class mailing list