Tuesday, June 26, 2012

Re: Slightly different models, merge or separate?

Anyone?

On Monday, June 25, 2012 10:12:43 AM UTC+2, 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+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: