laravel 5 - Eloquent Friendly Column Name -


we're transitioning 1 database another. table in our legacy database has column names less ideal, example:

some_crazy_name__xyz

in our new database, we'd have column name like:

somecrazyname

in short term, have work data our legacy database. @ point in near future, we'd switch on without having refactor of our eloquent code query different column names. example:

$model = mymodel::where('somecrazyname', '=', 1); 

i'm extending model class, implementing models provide map of terrible names friendly names:

class mymodel extends basemodel {     $columnmap = array(         'somecrazyname' => 'some_crazy_name__xyz'     ); } 

this works can use __get , __set in basemodel lookup properties in map, example:

$mymodel = new mymodel; // ... echo $mymodel->somecrazyname; 

however, doesn't work queries without having use map column names. i'm wondering if it's possible without having override of methods within illuminate\database\eloquent\model, illuminate\database\query\builder , illuminate\database\eloquent\builder deal columns, underlying query built maps correct column? after transition databases, can remove 1 piece of code rather remove potentially thousands of column name mappings.

this need: https://github.com/jarektkaczyk/eloquence/wiki/mappable

it's not mapping badly_named_columns something_useful, can used relational mappings:

// simple aliasing user::where('cool_name', 'value') // badname = ?  // relations, eg. user hasone profile user::where('first_name', 'jon') // search through related profiles table  // , mutators: $user->first_name == $user->profile->first_name  $user->cool_name = 'jon' // becomes $user->badname = 'value' $user->cool_name;  // 'jon' 

Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -