On 18 dic, 16:46, cricket <[email protected]> wrote: > 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. > I do need different fields for passport and National document. For example, the passport has an expiration date whereas the national document has not. So I think I should extend the Credential model. How could I do that? I know how to do it at the PHP side but I don't know how I should create the tables for that to work.
> > 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. Let's say I require the following: For passport: An alphanumeric code and an expiration date. For national document: A numeric code, no letters. I would like to be able to change the available view fields at runtime. For example, if I check the checkbox, the passport fields would appear and the national document fields dissapear. I could do it with JQuery or maybe with multipage forms, but the latter is another problem, isn't it? Apart from that, when you say, "create the association array" what do you mean? Thank you very much for your help. Andrés 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
