I've come across this situation with Oracle.
Here is how Class::DBI works in regards to has_a.
__PACKAGE__->has_a(
startdate => 'Date::Class',
inflate => sub { Date::Class->new(shift) },
deflate => 'some_method_name'
);
In the above example, you tell Class::DBI that the field
startdate should be 'modeled' by a Date::Class object.
Thus when a record is retrieved from the database
the value stored in the database is passed to the
anonymous sub, the anonymous sub is expected to
return an object reference to a Date::Class object.
When you construct an object from scratch
(you are wanting to insert a new record).
A common misconception is that you put a string
representing the date when in fact you must instead
put an object reference to Date::Class. For example:
Incorrect:
SomeTab->create({startdate => '07/08/03'});
Correct:
SomeTab->create({startdate => Date::Class->new('07/08/03')});
The deflate value if present is the name of a method of
the Date::Class object that will return a string of
the proper format for insertion into the database.
Or if Date::Class objects will stringify properly you
may leave the deflate key out all together.
We struggled with this for quite some time
only after reading through the Class::DBI code did I
come to this conclusion, as it is very poorly documented
One thing to note, you should replace Date::Class with
some real class which deals with dates.
For our purposes I used Date::EzDate, as it seemed to
easily support the most formats for parsing input
I subclassed Date::EzDate to get the default ouput
format that we needed to work.
I hope this helps if you need further assistance please
contact me, mgrubb-web-perlmonks at fifthvision dot net
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.