The question of whether it's a waste of time, or is this a useful
endeavor depends largely on your level tolerance for ugly prefixes all
over your code.  If you are going to do it, however, I would say
afterFind is not the answer.  A far better bet would be to subclass
the MySQL driver and override the resultSet() and fetchResult()
methods.  That's going to look something like this:

<?php

/*
 * app/models/datasources/dbo/dbo_mysql2.php
 */

uses('model/datasources/dbo/dbo_mysql');

class DboMysql2 extends DboMysql {

        function resultSet(&$results) {
                // code
        }

        function fetchResult() {
                // more code
        }
}

?>

Then in your database.php, set 'driver' => 'mysql'.  Lucky for you
those two methods are short, because you're on your own for the rest.
Especially the query conditions bit.


On Jan 11, 8:25 pm, Robby Anderson <[EMAIL PROTECTED]> wrote:
> After deciding mysql views won't work - well, technically they will,
> but its a not good solution - not portable (mysql only), not scalable
> (no indexing) and in general a risky proposition - I'm now on a new
> hunt: how to use Cake callbacks to support a $columnPrefix field in my
> models. Why? I have a legacy database to work with where each table's
> columns have a consistent column name prefix (ie, all tables in user
> start with usr_) and while Cake easily supports that, I want to use
> pretty syntax and clean code. Instead of being littered with usr_login
> and usr_first_name and such, I want login and first_name and other
> nice clean stuff.
>
> Am I crazy? Is this a silly, fruitless quest? Will converting data
> back and forth kill my performance more than using mysql views, no
> indexes and all? Is this just worthless, and should I just use my
> prefixed columns? I dunno, I dunno. But I'm game to find out. (And if
> you have answers for any of those questions ... I'm game to hear
> those, too.)
>
> So, my first trick was to parse the results of a find and strip them
> out using everyone's best friend afterFind(). Here are the first
> generation, brute force results that work on basic models and
> associations (haven't tested it very deeply 
> yet):http://bin.cakephp.org/saved/27230
>
> If you have comments about ways to optimize this, I'm all ears. Beyond
> that, here are the other steps as I see them:
>
> * Use the prefixStripper() in afterSave() to convert the data returned
> from saves.
>
> * Make beforeFind() and beforeSave() parse all the input parameters,
> and convert any non-prefixed column names into prefixed column names.
> These I suspect will be the harder ones to code to catch all the
> various cases.
>
> Again I ask, is this a waste of time, or is this a useful endeavor?
--~--~---------~--~----~------------~-------~--~----~
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