avenirer / CodeIgniter-MY_Model

Base model (MY_Model) for the Codeigniter framework.
324 stars 203 forks source link

Has_many_pivot get_relate on model in subFolder #272

Open vlatkoIT opened 6 years ago

vlatkoIT commented 6 years ago

I really appreciate the existence of this "model" library and recently tried and successfully integrated it in my Codeigniter 2 project. Maybe this issue is because I customized something or because I tend to keep my models organized in subfolders.

I created has_many_pivot relationship between two tables, with a pivot table containing only the two ids. What I had issue with was the foreign_model field, which is in a subfolder, so the string looks something like this subfolder/users_model. And I suppose you will understand what happens when you place the sting in this code: $subs[$the_local_key][$the_foreign_key] = $this->{$relation['foreign_model']}->where($foreign_key, $result[$foreign_key])->get();

Basically, the system was looking for $this->subfolder/users_model->where(...), but then I changed from $relation['foreign_model'] to $relation['foreign_model_name'] and everything was fixed. I don't know if this helps with anything, or if it is a bug fix as well, I thought to share it