usmanhalalit / pixie

Database query builder for PHP, framework agnostic, lightweight and expressive.
MIT License
672 stars 180 forks source link

insert() doesn't work with table alias #192

Open ArthurHoaro opened 6 years ago

ArthurHoaro commented 6 years ago

With an alias associated to a table, the insert query will use the table alias instead of its actual name.

How to reproduce

// Call this with an open DB connection
QB::table(['table' => 't'])->insert(['data' => 33]);

Actual result (MySQL)

PHP Fatal error: Uncaught PDOException: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'schema.t' doesn't exist

with generated SQL

INSERT INTO `t` (`data`) VALUES (?)

Expected result The full « table » name is used in the INSERT INTO query, such as:

INSERT INTO `table` (`data`) VALUES (?)

Use case It also affects updateOrInsert(), which is a great helper that can be used on complex queries, where table aliases are really convenient. Sorry, my use case is wrong, updateOrInsert() doesn't support joins, I don't know why I thought it would have. So this issue doesn't really matter, but it still feels like it should be addressed, for consistency.