-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
findAll: Include multiple joins to the same model without alias at the definition level. #8013
Comments
I have a similar issue. Sequelize uses twice the same alias in two different levels of the query, which causes an error as it is not able to find one of the referred columns. is there news on this? |
I have a similar issue. Is there anyway we can get this added? |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If this is still an issue, just leave a comment 🙂 |
Same issue here.. |
Any news? |
I have the same problem. |
You need to define the "intermediate model" which connects the two models together. So, beside having the User and Blog models you need the following: const BlogUsers = sequelize.define('blogUsers', {
role: Sequelize.STRING // Just an example, it is a optional column to the relation
})
// Correction many-to-many association
User.belongsToMany(Blog, { through: BlogUsers }
Blog.belongsToMany(User, { through: BlogUsers } |
same issue, any updates. to this issue ? |
similar issue, alias name have no effect |
Similar issue described here: #7754 |
What you are doing?
This is a contrived example but imagine a Blog that has many Users and each user can have many Blogs. Now I want to find all Blogs a user has and then bring back all the Users for that blog in a single query. I believe this should work by doing an
INNER JOIN
first to find all the affected blogs, then aLEFT JOIN
next to find all the users for each blog.Trouble is with doing x2 joins to the same table I get an alias conflict and nothing I can seem to try (I've read the docs, the code and frustratingly just tried random combinations of options) and nothing I can try seems to be able to reset the alias of one of these joins successfully.
I've tried adding
as
to alias but because I haven't set it in thebelongToMany
it doesn't seem to take affect. I shouldn't have to alias the relationship at the definition level to be able to alias at the query level (I think) but the docs seem to suggest otherwise.What do you expect to happen?
I should be able to alias a query without aliasing the definition. I've tried doing:
But even with this change I still get:
SequelizeBaseError: table name "blogUsers" specified more than once
even though I've supplied anas
option.What is actually happening?
Dialect: postgres
Database version: 9.6
Sequelize version: 3.30.2
PS. This is psuedo-code (might work but probably not), my example is a lot more complicated but tried to narrow down the example to just enough.
The text was updated successfully, but these errors were encountered: