Some of the reasons are: 1) Users can use the old version during a
transition period, so they are not forced to switch to the new version
for convenience, and 2) (important) a lot of backend-services (mostly
some php scripts executed as cron jobs) run with old code (and php
objects) and cannot just be "transformed".
I believe this should be a fairly common problem for projects
developed in CakePHP that have previously been developed with (or
without) something else, and cannot just change the database structure
like that...
I found a behavior that seems to accomplish this (almost), but I
really don't understand why you cannot define this in the models like:
class User extends AppModel {
var $_schema = array(
'attribute_name' => array('name'=>'field_name', 'type'=>
'string' ... )
);
}
Attribute_name would be used in the code, while field_name is the real
database table field. An example select query would be: SELECT
field_name AS attribute_name ...
This functionality shouldn't be rocket science IMHO, but maybe I'm
mistaken, and it's more complex than it seems?
On Apr 20, 6:53 pm, brian <[email protected]> wrote:
> I suppose the burning question is, why do you want both versions of
> the app using the same DB? That seems fraught with peril.
>
>
>
> On Mon, Apr 20, 2009 at 11:03 AM, jakobjp <[email protected]> wrote:
>
> > I am trying to map model attributes to database fields with different
> > names.
>
> > Example of regular CakePHP model:
> > User Model with attributes "id" and "firstname" would load the
> > appropriate values from same-named database fields "id" and
> > "firstname".
>
> > Example of my CakePHP mode:
> > User Model with aatributes "id" and "first_name" should load the
> > appropriate values from the fields "uid" and "firstname".
>
> > I know this is not perfect, but absolutely necessary because the new
> > and old application will use the existing database at the same time.
> > However, we do not want to continue using the old attribute names like
> > "uid" and "firstname".
>
> > I've tried playing around with the $_schema variable, but with no
> > luck :-(
>
> > Summary of this question: How to load a model attribute called X from
> > a database table field called Y?
>
> > Your help is much appreciated.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" 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
-~----------~----~----~----~------~----~------~--~---