tags:

views:

228

answers:

2

I want to create a model that has SOME attributes that are not stored in a database. For example, I want to maintain an "age" field in the model, but I only store birthday information in the database (I can calculate "age" once the DOB info has been loaded). I tried adding a simple attribute to a model extension, but as far as I can tell, it's ignored by CakePHP. What's the proper way to go about accomplishing this?

I'm a CakePHP novice, so forgive me if I'm missing something obvious.

+2  A: 

It's been a while since I dealt with Cake, but why not just implement a getAge() method?

timdev
I prefer this solution. It's explicit and documented in a logical location. `afterFind()` would work, of course, but it hides the logic more than I'd like. The availability of an `age` property would look like magic to new developers.
Rob Wilkerson
+6  A: 

I'd do it using the afterFind callback method in the model.

Marko
+1 That sounds promising. Just calculate age and stick it in some property.
timdev