The good ideas recently on the list regarding default values in
non-persisted objects led me to implement this in a three ways in
SPOPS:
1) Specify the default values in the class configuration
(metadata). This is completely portable across datasources (DBI, LDAP,
etc.) but leads to a synchronization problem between the object and
datasource.
2) Specify a record that contains the values you want to use as a
default. This isn't so bad -- you don't have to deal with all the
issues Schwern brought up regarding triggers, etc. But it's still a
little klunky (something else to maintain).
3) If you're using MySQL and SPOPS::DBI::MySQL, you can just say:
find_defaults => 'yes'
in the configuration and it will find out the defaults for fields in
that particular table. You change the defaults, the defaults in the
object change. Cool.
I tried this for PostgreSQL (using DBD::Pg) but the functionality for
finding table information seems to not retrieve the default
info. (Sent a note to the DBD::Pg author about this.)
It's pretty simple to implement this for different implementations --
that is, it's simple to join whatever the implmentation uses to
discover defaults to SPOPS. Whether it's simple to get this
information from a particular DBMS is another question...
These will be in the next version of SPOPS. The POOP-group gets proper
credit, of course :-)
Chris
--
Chris Winters (ch...@cw...)
Building enterprise-capable snack solutions since 1988.
|