Hello,
I have a People table and a Addresses table. A person can have one or
more addresses, but should at least have one, so there is a address_id
field in People.
Now, I would like to have a form to fill the name of a new person and
its address from the same place. I could use person.address.country, for
example (it works), but I would like to simply use person.country for
some reasons (I have a generic controller and generic views which can
make this kind of forms automatically if I give a list of fields, but it
has to be directly in the model).
I could add the “country” field to the model, but I have a lot of
fields I would like to “import”.
I tried to use the :include option, but mysql complains because I have
a field which has the same name in both People and Addresses table (and
it should stay this way).
I tried to generate model methods “on the fly” with define_method, but
I’ve not been able to do it, as I couldn’t write generic code to call
the corresponding method of another model. This is because I can’t know
the name of the method I’m currently in. Hope this is somewhat clear
So, my question is: how should I do that without writing a lot of
redundant code?
Thank you,
–
Yannick M. http://www.inma.ucl.ac.be/~majoros
Informaticien UCL/INMA-MEMA
4, avenue G. Lemaître
B-1348 Louvain-la-Neuve
Tel: +32-10-47.80.10
Fax: +32-10-47.21.80