CodeIgniter Forums

Full Version: Datamapper question - Searching multiple fields and/or tables
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]brent.fontaine[/eluser]
I looked around, and now, I'm not entirely sure what it is that I am looking for, so please excuse my ignorance.

I have a datamapper object defined as "Individual". The MySQL table has a unique ID, Given Names, Family Name, Birth Date. Everything works great between other models and relationships.

In the case of some individuals, they can get married, and have an alias. ie: Jane Doe is also known as Jane Smith. I want to keep record of both names, and still be able to search for either name. I also need to differentiate between the two, so I know which name matches the individual's birth certificate.

I was thinking about creating another object called "alias", as it is not a reserved name. I could easily set up a relationship, but this seems like using a sledgehammer to swat a fly. It would also make searching a bit more difficult.


Here's my question:
What is the most efficient way of handling this? Is it best to set up a join-table, and having a get-rule that always queries that table? Is it better to store a serialized array in the "Family Name" and "Given Names" fields? Does anyone have any other ideas?

Thanks in advance.

El Forum

[eluser]brent.fontaine[/eluser]
To answer my own question, this seems to break the datamapper principle of "each table is an object."
My original thought is that it would be more efficient, but this is likely not the case.

El Forum

[eluser]WanWizard[/eluser]
If you follow the normalization procedures, you'll notice that you have multiple names per individual. With leads to the conclusion that this must be a many-to-one relation.

And I think you can safely assume that the first/oldest name would match the name on the birth certificate, assuming that you record the date of change (and probably the reason). If not you'll need another way of identifying 'the first'.

Alternatively you create two relations between name and individual. One is a one-to-one recording the name at birth, the other a one-to-many containing all names.

This construction is not a problem for Datamapper.

El Forum

[eluser]brent.fontaine[/eluser]
Quote:Alternatively you create two relations between name and individual. One is a one-to-one recording the name at birth, the other a one-to-many containing all names.

Thanks for the reply WanWizard. I appreciate the help!