I'm not 100% sure I understand the situation, but it sounds to me like 
you're on the way to re-inventing the Entity Attribute Value DB pattern, 
which is wikipedia and there's a CakePHP example here  
http://bakery.cakephp.org/articles/abalonepaul/2011/10/11/eav_behavior 

As you realized, implementing your own dynamic data descriptions comes with 
various complications and overheads.

Also, you might want to look into the Single Table Inheritance pattern, 
STI, also on Wikipedia - basically you have multiple models working from 
the same table, and you can  tweak their callbacks to give 
different behavior - see  
http://bakery.cakephp.org/articles/santino83/2011/02/19/behavior_for_model_inheritance_the_missing_feature
 

Hopefully these  ideas will give you some inspiration on the best way 
forward!


On Monday, 25 June 2012 09:12:43 UTC+1, Poyan Nabati wrote:
>
> I have a question regarding more the design of the back-end rather than 
> specifically how to implement it. 
>
> I'm creating a life tracker of sorts. The purpose is to have a single 
> application to help you keep track of things that are important to you long 
> term.
>
> I want to be able to track a wide array of different things.
>
> For instance;
>
>
>    - What type of exercise did I do? (Fixed: Gym, Running or Other)
>    - Did I meditate today? (Boolean measurement)
>    - What was my weight today? (Numeric measurement)
>    - What's one good thing about today? (String "measurement")
>    
> So for each goal you have a single specific type of measurements.
>
> *How should I implement this on the backend?*
>
>
>    - *Two models.* I thought of having two models, Goal and Measurement, 
>    where Measurement has a corresponding field in the database called "value" 
>    that's agnostic of it's contents (in other words, a VARCHAR that I 
>    interpret differently depending on context). I believe, however, that this 
>    approach will create a lot of special code for each of the different cases 
>    down the line. 
>    - *Many models.* Another way to do it would be to create 
>    NumericMeasurement, BooleanMeasurement etc etc for each of the different 
>    measurement-types. In Goal I could have a field that indicates the type 
> and 
>    create the association Goal hasMany (each of the measurement types). Do 
> you 
>    see any problems with this approach?
>
> Is there another, better approach that I haven't thought about?
>
> How would you solve this?
>

-- 
Our newest site for the community: CakePHP Video Tutorials 
http://tv.cakephp.org 
Check out the new CakePHP Questions site http://ask.cakephp.org and help others 
with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscr...@googlegroups.com For more options, visit this group at 
http://groups.google.com/group/cake-php

Reply via email to