[Dbix-class] question about InflateColumn::DateTime

Christopher H. Laco claco at chrislaco.com
Tue Nov 7 19:02:56 GMT 2006


Jess Robinson 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 =3D $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 =3D $c->resultrow->date_of_birth;
> $dob->set_month([new month]);
> $c->resultrow->date_of_birth($dob);
> $c->resultrow->update;
> =

> =

> Jess

So, if I read that correctly, then every call to ->date_of_birth returns
 a newly inflated object, rather than just a reference to the same
inflate object?

In other words:

print ref $c->resultrow->date_of_birth;
print ref $c->resultrow->date_of_birth;
print ref $c->resultrow->date_of_birth;

would produce 3 completely new/seperate inflated objects?

Maybe this is something that should go on a TODO list.
I would suspect there's no good reason to inflate something more than
once per row. This would mean that people could start using those fields
like the original poster expected them too and not have to worry bout
reassigned the objects back into the column for a deflate cycle.

Of course, I could be completely missing the point. :-)


-=3DChris

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://jules.scsys.co.uk/pipermail/dbix-class/attachments/20061107/38=
5ca0c8/signature.pgp


More information about the Dbix-class mailing list