Reputation: 755
I have this users table below.
In phalcon, is it possible to map columnnames so that i can remove all the prefix names when executing all model related processes? In YII, this is doable. so lets say,
$user->id will point to $user->tbl_user_id; $user->fullname will point to $user->tbl_user_fullname; $user->phone will point to $user->tbl_user_phone;
I have no problem calling the table name since in the model you can specify the getSource(). I tried column mapping i found online but not working and not sure if its ideal.
Also, Will this cause possible issue if i'm going to implement it this way? Any known disadvantages?
PHP VERSION
PHP 5.4.44-0+deb7u1 (cli) (built: Aug 16 2015 09:51:53) Copyright (c) 1997-2014 The PHP Group Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
Upvotes: 0
Views: 424
Reputation: 2003
You can map your database column names to your internal Phalcon naming:
Put this in your User
model
public function columnMap()
{
return [
// database column name => phalcon name
'tbl_user_id' => 'id',
'tbl_user_fullname' => 'fullname',
'tbl_user_phone' => 'phone',
];
}
Check the documentation for more information about the column mapping.
The ORM supports an independent column map, which allows the developer to use different column names in the model to the ones in the table. Phalcon will recognize the new column names and will rename them accordingly to match the respective columns in the database. [...].
Upvotes: 3