CodeIgniter Forums
Joining two models with same column names - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Joining two models with same column names (/showthread.php?tid=79075)



Joining two models with same column names - dhmm - 04-17-2021

On CI 4 , when we have 2 Models that are joined betweene but they have same names how can we join them using CI model's

Let's suppose we have

Account [ account_id, name, city_id, updated_at....]
City [ city_id, name, updated_at....]

Here the 2 models have fields name , updated_at ...
When we want to retrieve data how can we do this to avoid conflicts, because when I'm doing it overriding values.

Thank you


RE: Joining two models with same column names - MGatner - 04-17-2021

You should be able to specify aliases in a select() method:
$model->select('cities.name AS city_name')...