This technique has been useful to me so I thought I would mention it in
case it would be useful to you.

I needed to display some fields that were derived from 2 different
tables.

I could have created a Model for one of the tables - and added logic in
the afterFind() method to insert the new fields into results array.

But using a view on the database to construct this makes it much
simpler.

Use something similar to this DDL to create it.
======
CREATE OR REPLACE VIEW v_people AS
select  p.peopleID,
                CONCAT_WS('-', h.display_id, p.disp_order) display_id,
                p.last_name,
                p.first_name,

                p.birthday,
                TIMESTAMPDIFF(YEAR,p.birthday, CURDATE()) age,

                CASE
                        WHEN p.phone1           <> '' THEN p.phone1
                        WHEN p.phone2           <> '' THEN p.phone2
                        WHEN p.phone3           <> '' THEN p.phone3
                        WHEN h.phone_num1       <> '' THEN h.phone_num1
                        WHEN h.phone_num2       <> '' THEN h.phone_num2
                        ELSE h.phone_num1
                END primary_phone,
from people p, household h
where h.household_id = p.household_id
========

And then create your model for this view and all the fields will be
retrieved as if they were normal table fields.

Much simpler than trying to do that in the Model logic!

Or did I miss a better way to do something like this in cake itself?


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to