[Bast-commits] r5831 - DBIx-Class/0.08/trunk/lib/DBIx/Class

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Sat Mar 28 22:05:35 GMT 2009


Author: ribasushi
Date: 2009-03-28 22:05:35 +0000 (Sat, 28 Mar 2009)
New Revision: 5831

Modified:
   DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm
Log:
Clarify DBIC behavior wrt RDBMS default values

Modified: DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm
===================================================================
--- DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm	2009-03-28 21:46:34 UTC (rev 5830)
+++ DBIx-Class/0.08/trunk/lib/DBIx/Class/Row.pm	2009-03-28 22:05:35 UTC (rev 5831)
@@ -75,15 +75,25 @@
 be turned into objects via new_related, and treated as if you had
 passed objects.
 
-Please note that if a value is not passed to new, DBIC will have no knowledge
-of the value unless the value is reloaded, creating the possibility of the row
-object differing from the database value if column defaults are used. To avoid
-this issue you can either pass an explicit undef for nullable columns with a
-NULL as default, or simply call L</discard_changes> on the row object after
-insertion.
-
 For a more involved explanation, see L<DBIx::Class::ResultSet/create>.
 
+Please note that if a value is not passed to new, no value will be sent
+in the SQL INSERT call, and the column will therefore assume whatever
+default value was specified in your database. While DBIC will retrieve the
+value of autoincrement columns, it will never make an explicit database
+trip to retrieve default values assigned by the RDBMS. You can explicitly
+request that all values be fetched back from the database by calling
+L</discard_changes>, or you can supply an explicit C<undef> to columns
+with NULL as the default, and save yourself a SELECT.
+
+ CAVEAT:
+
+ The behavior described above will backfire if you use a foreign key column
+ with a database-defined default. If you call the relationship accessor on
+ an object that doesn't have a set value for the FK column, DBIC will throw
+ an exception, as it has no way of knowing the PK of the related object (if
+ there is one).
+
 =cut
 
 ## It needs to store the new objects somewhere, and call insert on that list later when insert is called on this object. We may need an accessor for these so the user can retrieve them, if just doing ->new().




More information about the Bast-commits mailing list