limit option produces 'missing FROM-clause entry for table' error
See original GitHub issueIssue Description
findOne produces ‘missing FROM-clause entry for table’ error on PostgreSQL.
What are you doing?
User.js
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('User', {
name: {
type: DataTypes.STRING,
allowNull: false,
},
}, {
tableName: 'users',
paranoid: false,
timestamps: false,
});
User.associate = function(models) {
// associations can be defined here
User.hasMany(models.Project, {
foreignKey: {
name: 'userId',
allowNull: false,
},
});
};
return User;
};
Project.js
module.exports = (sequelize, DataTypes) => {
const Project = sequelize.define('Project', {
value: {
type: DataTypes.STRING,
allowNull: false,
},
}, {
tableName: 'projects',
paranoid: false,
timestamps: false,
});
Project.associate = function(models) {
// associations can be defined here
Project.belongsTo(models.User, {
foreignKey: {
name: 'userId',
allowNull: false,
},
});
};
return Project;
};
I’d like to find any (findOne
) user without projects.
const user = await models.User.findOne({
where: {
'$Project.value$': { [models.Sequelize.Op.eq]: null }
},
include: [{
model: models.Project,
required: false,
}],
});
What do you expect to happen?
A user without projects.
What is actually happening?
error: missing FROM-clause entry for table "Projects"
Additional context
findAll
works as expected.
const users = await models.User.findAll({
where: {
'$Project.value$': { [models.Sequelize.Op.eq]: null }
},
include: [{
model: models.Project,
required: false,
}],
});
Environment
- Sequelize version: 5.21.1
- Node.js version: v10.16.3
- Operating System: macOS/Docker
- If TypeScript related: TypeScript version: no
Issue Template Checklist
How does this problem relate to dialects?
- I think this problem happens regardless of the dialect.
- I think this problem happens only for the following dialect(s):
- I don’t know, I was using PUT-YOUR-DIALECT-HERE, with connector library version XXX and database version XXX
Would you be willing to resolve this issue by submitting a Pull Request?
- Yes, I have the time and I know how to start.
- Yes, I have the time but I don’t know how to start, I would need guidance.
- No, I don’t have the time, although I believe I could do it if I had the time…
- No, I don’t have the time and I wouldn’t even know how to start.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:7
- Comments:26 (7 by maintainers)
Top Results From Across the Web
Fix “ERROR: missing FROM-clause entry for table” in ...
Another way to fix it is to use an alias for the column: (SELECT TeacherName t FROM Teachers) UNION (SELECT StudentName FROM Students)...
Read more >PG::UndefinedTable: ERROR: missing FROM-clause entry for ...
I am trying to get a list of uniq patients who have submitted an esas_assessment , sorted by the time the esas_assessment was...
Read more >Missing FROM-clause entry for table in postgres CTE
You are facing with SQL Error [42P01]: ERROR: missing FROM-clause entry for table "a_cte" error because you never select from a_cte .
Read more >PostgreSQL : Documentation: 9.6: SELECT
If the LIMIT (or FETCH FIRST ) or OFFSET clause is specified, the SELECT ... If RETURNING is omitted, the statement is still...
Read more >Re: " Adding missing FROM-clause entry for table .... " problem.
> "allow_implicit_from", with options "ok" (completely permissive),. > "notice" (the current behavior), and "error" (disallow it). That's a workable compromise ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Produces:
And the error:
error: missing FROM-clause entry for table "Projects"
Produces:
Hi,
subQuery: false,
helps me, but it was not obvious.