aditya.internet
05-01-2008, 11:09 AM
Hi,
I have implemented user information storage in following manner:
profiles
---------
id
email
password
profile_attributes
------------------
id
name
field_type
profile_options
----------------
id
profile_attribute_id
name
profile_details
---------------
profile_id // This record is of which profile
profile_attribute_id // This record indicates which attribute (gender etc)
profile_option_id // This value is set if the user selected from drop down
value // This value is filled when a user enters a text value
So this means my profile_attributes table has all the attributes for a profile.
When storing the data for a particular attribute, references are stored in "profile_details" table.
For example:
profiles
--------
id: 1
email: boy@website.com
profile_attributes
----------------------
id: 1
name: gender
field_type: select
profile_options
----------------
id: 1
profile_attribute_id: 1
name: Male
id: 2
profile_attribute_id: 1
name: Female
profile_details
---------------
id: 1
profile_id: 1
profile_attribute_id: 1
profile_options_id : 1
value: null
I would like to know if there is any down side of having this implementation. I have gone ahead with this approach keeping in mind scalability factors in mind and few other important things. I dint wanted to have a table with columns of each attribute coming out to be 30 columns plus.
And the most important thing I need help with is how should I query profiles with certain attributes.
Like all the profiles with gender male and country Germany.
Now I am not sure how to construct a query for that.
I am looking forward to doing this in a single query but have multiple where clauses is creating a problem in fetching results.
select from profiles
join profile_details on(profiles.id = profile_details.profile_id)
where (gender = 'Male') and (country = 'Germany')
This fails as it tries to get profiles with joining profile_details and looks for records which matches all the where clauses that is not possible a profile_detail to match both gender and country condition.
And if I change the clauses to "or" comparison then it gets me both:
gender: male and country: any
gender: any and country: Germany
There are several other ways to go around doing this like sub queries etc but I am looking for a better approach to get this working.
I will be glad to add clarifications if required.
Thanks in advance..
I have implemented user information storage in following manner:
profiles
---------
id
password
profile_attributes
------------------
id
name
field_type
profile_options
----------------
id
profile_attribute_id
name
profile_details
---------------
profile_id // This record is of which profile
profile_attribute_id // This record indicates which attribute (gender etc)
profile_option_id // This value is set if the user selected from drop down
value // This value is filled when a user enters a text value
So this means my profile_attributes table has all the attributes for a profile.
When storing the data for a particular attribute, references are stored in "profile_details" table.
For example:
profiles
--------
id: 1
email: boy@website.com
profile_attributes
----------------------
id: 1
name: gender
field_type: select
profile_options
----------------
id: 1
profile_attribute_id: 1
name: Male
id: 2
profile_attribute_id: 1
name: Female
profile_details
---------------
id: 1
profile_id: 1
profile_attribute_id: 1
profile_options_id : 1
value: null
I would like to know if there is any down side of having this implementation. I have gone ahead with this approach keeping in mind scalability factors in mind and few other important things. I dint wanted to have a table with columns of each attribute coming out to be 30 columns plus.
And the most important thing I need help with is how should I query profiles with certain attributes.
Like all the profiles with gender male and country Germany.
Now I am not sure how to construct a query for that.
I am looking forward to doing this in a single query but have multiple where clauses is creating a problem in fetching results.
select from profiles
join profile_details on(profiles.id = profile_details.profile_id)
where (gender = 'Male') and (country = 'Germany')
This fails as it tries to get profiles with joining profile_details and looks for records which matches all the where clauses that is not possible a profile_detail to match both gender and country condition.
And if I change the clauses to "or" comparison then it gets me both:
gender: male and country: any
gender: any and country: Germany
There are several other ways to go around doing this like sub queries etc but I am looking for a better approach to get this working.
I will be glad to add clarifications if required.
Thanks in advance..