Re: model relationship for optional details

2008-04-22 Thread Ariel Arjona

Thanks for the replies.

Aaron, could you please elaborate about the conditions in the
validation?

Regards,
Ariel

>
> w.r.t the hasMany relation, as long as you omit conditions from your
> validation and your SQL schema is set properly, you will not run into
> any problems.
> /a
>
> 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 cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: model relationship for optional details

2008-04-21 Thread aaron bauman

in your 'options' to Form::input, you can pass a special option
'empty'.
this creates an option element will have no value attribute and sets
the innerText to the array value.
for example
array('options' => array('empty' => ' - None - '))
will generate html like
...
- None -
...

you can simply set 'empty' => true to generate an empty option at the
front of the select list

w.r.t the hasMany relation, as long as you omit conditions from your
validation and your SQL schema is set properly, you will not run into
any problems.
/a


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 cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: model relationship for optional details

2008-04-21 Thread [EMAIL PROTECTED]

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 cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---