Hopefully, the table structure at the end is self-explanatory:
I want to be able to do something like this:
@panelist = Panelist.first
puts @panelist.age
$stdout> 30
puts @panelist.gender
$stdout> M
Is this doable through OTB Rails associations (polymorphic or
otherwise), Or
will I have to do some custom coding in order to achieve this?
Thanks
mysql> select * from panel_attribute;
±-------------------±---------------------+
| panel_attribute_id | panel_attribute_name |
±-------------------±---------------------+
| 1 | age |
| 2 | gender |
±-------------------±---------------------+
2 rows in set (0.00 sec)
mysql> select * from panelist;
±------------±--------------+
| panelist_id | panelist_name |
±------------±--------------+
| 1 | user1 |
| 2 | user2 |
±------------±--------------+
2 rows in set (0.00 sec)
mysql> select * from panelist_attribute;
±----------------------±-------------------------±------------±-------------------+
| panelist_attribute_id | panelist_attribute_value | panelist_id |
panel_attribute_id |
±----------------------±-------------------------±------------±-------------------+
| 1 | 30 | 1
| 1 |
| 2 | M | 1
| 2 |
| 3 | 31 | 2
| 1 |
| 4 | F | 2
| 2 |
±----------------------±-------------------------±------------±-------------------+
4 rows in set (0.00 sec)
mysql>