#10227: OneToOne fields with null=True raise DoesNotExist exception on related
model
---------------------------------------------------+------------------------
          Reporter:  rvdrijst                      |         Owner:  nobody     
                    
            Status:  new                           |     Milestone:             
                    
         Component:  Database layer (models, ORM)  |       Version:  1.0        
                    
        Resolution:                                |      Keywords:  onetoone 
related expection null
             Stage:  Design decision needed        |     Has_patch:  1          
                    
        Needs_docs:  0                             |   Needs_tests:  0          
                    
Needs_better_patch:  0                             |  
---------------------------------------------------+------------------------
Comment (by gsakkis):

 I ran into the same problem although in my case a hypothetical
 `related_null=True` would not help; a new default object would have be
 created. So instead of `related_null` I wrote a OneToOneField that uses
 `related_default`, a callable `lambda instance: value`. I posted the
 snippet at http://gist.github.com/601977.

 To me this seems more elegant, not only because it is a generalization of
 the `related_null` (just set `related_default=lambda instance: None`) but
 because `null` (and by association `related_null`) is a DB-level
 parameter, it determines whether a DB column is created as NULL or NOT
 NULL. In the case of a OneToOneField, the related model does not have a
 column linking to the model where the OneToOneField was defined (no
 `shop_id` column in the place table), so it doesn't make sense to say it's
 null.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/10227#comment:10>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to django-upda...@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to