Hello,

I'm the person who started this thread on the Catalyst ML. 

The original problem is that trying to display the field of an object related 
by belongs_to, Template Toolkit would autovivify the object if it didn't 
already exist. So given a Transaction object r, just trying to display 
r.customer.b_company would do an sql insert and create a blank customer object, 
if the column r.customer was 0 (i.e. if there was no customer object).

The docs did not explain that such side-effects were entailed by "doing the 
right thing". It seemed to be a bug to me but I understand now it is more just 
a problem with the docs. The might_have docs are also a bit lacking in fact one 
sentence stops midway through.

It seems my options are to do one of the following.
1. Allow NULL for that column so belongs_to knows it is optional. 
2. Use might_have instead of belongs_to, if there is no other difference in its 
operation.
3. Solve it all in the search call before going to the template. Maybe same 
autovivification will happen though.
4. Create a dummy customer of ID 0.

My original reasoning for not allowing NULL is so that I wouldn't get a crash 
if trying to display/reference a null. Since it will be operated by someone not 
familiar with the concept of NULL it seemed a bit dangerous to use it. At any 
rate now I have a system in production and don't want to make big changes to 
it. probably #4 is simplest but also I would like to know if might_have can be 
used as a drop-in replacement for belongs_to that just won't do 
autovivification. Thanks for your help.

Sincerely,

Matt Rosin


       
____________________________________________________________________________________
Looking for a deal? Find great prices on flights and hotels with Yahoo! 
FareChase.
http://farechase.yahoo.com/
_______________________________________________
List: http://lists.rawmode.org/cgi-bin/mailman/listinfo/dbix-class
Wiki: http://dbix-class.shadowcatsystems.co.uk/
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/trunk/DBIx-Class/
Searchable Archive: http://www.mail-archive.com/[email protected]/

Reply via email to