[Dbix-class] RFC: Inflating user-supplied values

Jason Kohles email at jasonkohles.com
Mon May 7 17:56:02 GMT 2007


On May 7, 2007, at 9:02 AM, Matt S Trout wrote:

> On Sun, May 06, 2007 at 09:16:41AM -0400, Jason Kohles wrote:
>> So everybody probably saw my confusion with inflation from yesterday,
>> and while it is all working now (thanks Claco!) I have to admit I
>> still find the behavior counter-intuitive at best.  I guess when I
>> was just inflating DateTime objects it made more sense, since the
>> inflated values were so much more complex than the representation
>> that was stored in the database, but when I started using
>> DBIx::Class::InflateColumn::Currency, it seemed odd to me that
>> '$10.00' would be inflated to a Data::Currency object if it came from
>> the database, but not if it came from the user.  I've fixed this for
>> my immediate need by writing an HTML::FormFu::Inflator subclass that
>> parallels DBIx::Class::InflateColumn::Currency, but going forward I'd
>> like to avoid repeating so much code, so I've come up with an idea to
>> extend DBIx::Class::InflateColumn to allow user-provided values to be
>> inflated the same way that database values are.
>
> Well, if you call $obj->inflated_field('$10.00');
>
> then do $obj->inflated_field; the second call will return the  
> inflated object.
>
> I'm not sure I see what the problem you're trying to solve is?
>
The original problem I was having was a combination of  
DBIx::Class::FormFu and DBIx::Class::InflateColumn::Currency.  When a  
form was submitted that had dollar amounts in the inflated fields,  
the database would get updated with 0's in all the currency columns,  
DBIC_TRACE revealed that this was because the un-inflated values were  
being passed to the database and MySQL was setting those fields to 0  
since it considered the data it was getting to be non-numeric as it  
started with a '$'.  My attempts to locate the source of the problem  
(and the responses I got to my initial post) all suggested that only  
data coming from the database would be inflated and that if I wanted  
to set it manually I needed to do $obj->inflated_field 
( Data::Currency->new( '$10.00' ) ).  Since you indicated this isn't  
the case, I built a minimal test case this morning and confirmed that  
indeed, this should just work, so I guess now I need to go back to  
trying to figure out why the wrong information is being passed to the  
database in the larger application.

So it appears the RFC was actually an attempt to add functionality  
that does indeed already exist, and now I get to go back to debugging...

-- 
Jason Kohles
email at jasonkohles.com
http://www.jasonkohles.com/
"A witty saying proves nothing."  -- Voltaire





More information about the Dbix-class mailing list