i usually do the same thing, and if - using your example - a user
didn't have a department to belongTo, I would just leave the
department_id field  as 0; or i suppose if you were really worried
about it you could have a department called "none", but that's
probably silly

On Apr 21, 1:31 pm, Ariel Arjona <[EMAIL PROTECTED]> wrote:
> Hello,
>
> I seem to run often into the situation where I have a field certain
> fields in my tables that are basically drop down lists, but they are
> optional. I'm wondering what's the correct way to manage this.
>
> Here's an example:
>
> I have a User model and a Department model. Not every user has a
> department (ie. contractors, temps). Right now the tables look like
> this:
>
> users:
> id - int
> department_id - int nullable
> name - varchar
> etc etc.
>
> departments:
> id - int
> name - varchar
>
> and the model associations are
> User belongsTo Department
> Department hasMany User
>
> I'm wondering if this is the correct approach. Does hasMany expects a
> value on the other side? are nullable FKs a bad practice? So far I've
> run into some cosmetic weirdness in views. The next field folds into
> the null field. Also I've had to add modify my views like so:
>
> echo $form->input('department_id', array('options' => array('NULL'=>'-
> None-') + $departments));
>
> This still feels a bit clunky, but not as much as does setting it up
> as HABTM. Is there an easier/more correct way?
>
> Thanks in advance,
> Ariel
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to