Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

union-query on multiple databases #17353

Open
Rakasch opened this issue Oct 16, 2023 · 3 comments
Open

union-query on multiple databases #17353

Rakasch opened this issue Oct 16, 2023 · 3 comments
Labels
Milestone

Comments

@Rakasch
Copy link

Rakasch commented Oct 16, 2023

Description

Tried to create a union query on two tables that are on different databases and get an error.
It does not seem to take into account the other DB prefix.

simplified Example:

CatsTable on DB cats.
DogsTable on DB dogs.

I did define the DB name in each Table with defaultConnectionName():
I can successfully query the tables individually.

Now I want to do a union query.

$catQuery = $this->fetchTable('Cats')->find()->order(['created'])->limit(10);
$dogQuery = $this->fetchTable('Dogs')->find()->order(['created'])->limit(10);

$query = $catQuery->unionAll($dogQuery)->order(['created'])->limit(10);

I get this error:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'catsDb.dogsTable' doesn't exist.

CakePHP Version

4.4.18

PHP Version

8.1

@Rakasch Rakasch added the defect label Oct 16, 2023
@Rakasch
Copy link
Author

Rakasch commented Oct 16, 2023

ok seems thats basically not supported. Only with hacks :(
Joins dont work either.
#15515

@Rakasch Rakasch closed this as completed Oct 16, 2023
@othercorey othercorey added this to the 4.5.1 milestone Oct 16, 2023
@Rakasch
Copy link
Author

Rakasch commented Oct 16, 2023

I can do a workaround like this:
image

So basically the query works, cake just doesnt take the db prefix of defaultConnectionName.
Same issue for joins.

@Rakasch Rakasch reopened this Oct 16, 2023
@markstory
Copy link
Member

We don't support joins/unions across databases. Database connections could be in different physical machines and there is no way for the ORM to safely abstract operations across databases.

@markstory markstory added database and removed defect labels Oct 16, 2023
@markstory markstory modified the milestones: 4.5.1, 4.5.2 Nov 15, 2023
@markstory markstory modified the milestones: 4.5.2, 4.5.3 Dec 15, 2023
@markstory markstory modified the milestones: 4.5.3, 4.5.4 Jan 20, 2024
@markstory markstory modified the milestones: 4.5.4, 4.5.5 Mar 6, 2024
@markstory markstory modified the milestones: 4.5.5, 4.5.6 May 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants