Skip to content

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

@ArthurHoaro

Description

@ArthurHoaro

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.

Metadata

Metadata

Assignees

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions