On Fri, Dec 17, 2010 at 11:20 PM, Andr?s Manikis
<[email protected]> wrote:
> Hello.
> I have the following questions.
>
> Let's suppose I have, say, a person model which has an id, a name and a
> boolean that tells whether this person is native from a specific country or
> not (for example, native from Argentina or not).
>
> In the case of being native, he has a national document, otherwise, he has a
> passport.
>
> So, the first question: is ok to have a person model that has one passport
> or one national document? Maybe I should make this person to have one
> generic document which then can be a passport or a national document.

You do either. That is, a model can have a $hasOne association that is
empty. Your data from a find() would just return an empty array for
Passport or NationalDocument (whichever didn't exist). But, if the
model can only have one or the other, it might be simplest to create a
more general model, eg. Credential. That model could either be
extended by Passport and NationalDocument, or it could be associated
with a CredentialType model whose table was a list of types. It really
depends on whether you need other firleds for Passport and
NationalDocument.


> The second question would be: how can I change the form fields dynamically
> in the view depending of the person being native or foreign? I mean, if the
> person is native, the "add person" form should have a "national document"
> field present whereas if the person is foreign, the field present should be
> "passport" instead of "national document".

What information do you require in either case? If it's only, eg. a
number, you could use a single field in conjunction with a checkbox,
neither of which directly corresponds to an actual Person field. In
beforeValidate, look at the checkbox value and create the association
array according to it. Then assign to it the text element value. Can't
really suggest much more without knowing what the information is that
you require, though.

Check out the new CakePHP Questions site http://cakeqs.org and help others with 
their CakePHP related questions.

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