Monday, July 23, 2012

Re: Ingherited models that filter active users/records?

Thanks to you and Mike and Jeremy for responses.  Not only do I have confirmation that I was headed in the right direction, model-wise, with some examples, but you have prodded me to expand my use of MySQL constructs.  To date I haven't used a VIEW, but it would seem that one big advantage could be taking the filter logic out of Cake (no always the fastest!) and shifting it to the DB back end. Not quite a stored procedure but maybe same effect.

Thanks again!

Jim


On Saturday, July 21, 2012 7:03:04 AM UTC-7, Ratty wrote:
On 20/07/12 17:44, geste wrote:
I have a business system with a table called "People" and where we retain records of a Person even when they leave our organization.  Each record has an "active" attribute that indicated if somebody is active (Duh!).

However, I find myself writing a lot of snippets in controllers that essentially go "WHERE active = '1'" and that seems like it could be a pain and error-prone over time.

What I'd like to do is leave "People" alone but create a new model or model called "Users" that simply flters People for active=1.  And maybe a corresponding model that is OldUsers and feteches active=0.

I started to implement something like this at the controller level but then asked myself why not implement at Model level.  Does this seems liek a rational approach.  Can anyone point to some good examples outside of basic API docs?

Thanks,

Jim

--
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
You *could* implement this as 2 database views as opposed to tables. So 'Users' and 'OldUsers' would simply be 2 views on the 'People' table.

In MySQL this becomes...  CREATE VIEW OldUsers AS SELECT * FROM People WHERE active='0';

OldUsers is then effectively a read-only table and CakePHP is quite happy to generate a model for it.


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