I have a situation where I have a number of tasks (e.g. installing a
toilet, installing new carpet) that share common properties (title,
category, etc.) that are stored in the database. There are also
properties that are static for some tasks but dynamic for others (e.g.
the cost of installing a toilet is static, but the cost of installing
new carpet depends on how many square feet you're carpeting, a datum
we have to get from elsewhere in the database). Setting aside the
database for a moment, the classical object-oriented solution would be
subclasses that override the cost() function to return the right
information: ToiletClass.cost() could just return $250, while
CarpetClass.cost() would look up the square footage and return a cost
based on that.

The question is: What's the Cake Way to handle something like this?
Ideally I'd like to be able to call something like $this->Task-
>findAllByCategory($someCategory) in my controller and have "cost" be
one of the items in the returned array. Is there a way to put a column
in my tasks table that will tell Cake to load a particular subclass of
Task? (In which I could define a "cost" method and call it in
afterFind.) Or am I better off using just one class for Task but
having a bunch of behavior classes that define different cost()
implementations? And if behaviors are the way to go, how do I tell my
one Task class that it actsAs a particular behavior based on something
fetched from the db? (I could literally put an "actsAs" column on the
table, I suppose, but that feels hacky and brittle.)

I'm new to Cake, so I'm hoping that this is something that others have
encountered. Unfortunately I didn't come up with anything obviously
applicable after searching, so I'm posting here.

Thanks,

noah

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to