Welcome Guest, Not a member yet? Register   Sign In
Select with alias in model in CI 4
#1

Hello, I have this strange problem with a query on my CI4 project. There is a page that is really slow, so I've decided to print the sql query to see what's wrong with that and I've noticed this:

Code:
SELECT `mov`.*
FROM (`Movements`, `Movements` as `mov`)
JOIN `Articles` as `art` ON `art`.`id` = `mov`.`articleId`
GROUP BY `mov`.`id`
ORDER BY `id` desc
LIMIT 20

The table name was repeated and this causes a huge slowing of the table.


The code I've used in my model is:

Code:
$this->select('mov.*');
$this->from('Movements as mov');
$this->join('Articles as art', 'art.id = mov.articleId');
$this->groupBy("mov.id");
$this->orderBy("id");
$this->limit(20);

If I don't use alias query works good, but it's a little bit annoying to repeat the entire table name every time in the query:

Code:
$this->select('Movements.*');
$this->join('Articles as art', 'art.id = Movements.articleId');
$this->groupBy("Movements.id");
$this->orderBy("id");
$this->limit(20);

What am I missing?
Thank you
Reply


Messages In This Thread
Select with alias in model in CI 4 - by damiano - 03-04-2021, 09:59 AM



Theme © iAndrew 2016 - Forum software by © MyBB