Working with Models in SubFolders
Hi,
In my APPPATH.models/Company_model.php, I am adding a relation to City_model which lives in APPPATH.models/Geography/City_model.php. Trying to relate with: $this->has_one['city'] = 'Geography/City_model';.
But it gives me an error. Stack says:
RuntimeException [ 0 ]: Unable to locate the model you have specified: City_model
/home/vagrant/Code/eys-rebased/vayes-eys/system/core/Loader.php [ 344 ]
APPPATH/core/MY_Model.php [ 1421 ] » CI_Loader->model(arguments)
model city_model
name geography_city_model
Apparently it converts my Geography/City_model.php to geography_city_model which makes it not found.
Thanks for any tip.
Use lower case for your folder names. You may get away with just renaming the folder but I would recommend to also change it in your code.
I changed the folder name from Geography to geography and make required updates but it didn't work. But I might be found and fix the problem. Check it please. I really wonder if I get it right :)
1405. // $model_dir = $model['model_dir'];
1406. $foreign_model_name = $model['foreign_model_name'];
+ if($model['model_dir']) {
+ $this->load->model($model['model_dir'].strtolower($model['foreign_model']), $foreign_model_name);
+ } else {
+ $this->load->model($foreign_model, $foreign_model_name);
+ }
$foreign_table = $this->{$foreign_model_name}->table;
$foreign_key = $this->{$foreign_model_name}->primary_key;