Conflict with column names using CI 4 models |
Hi community.
I have these tables where they have column names "name" accounts ( ... , name ,...) cities( .... , name ,...) I'm using CI models and entities and when I'm selecting data like this Code: $accountModel = new AccountModel(); in the result I have only 1 column named "name" which is overrided from the cities' column. One solution is to use column names like this city_name,city_id , account_id , account_name but for me it isn't good practice. What can I do ?
That's not really a problem with the CI 4 model class. You would have the same conflict with your column names if you would use the mysql functions directly. You can try to call select() (from the query builder) by specifying new column name with the AS keyword. See this example:
PHP Code: $builder->select('(SELECT SUM(payments.amount) FROM payments WHERE payments.invoice_id=4) AS amount_paid', false);
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/ |
Welcome Guest, Not a member yet? Register Sign In |