You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been trying to figure this out for 2 days, and couldn't find it anywhere in the documentation, so I think this is a feature request. I think this might require a breaking change though, so maybe it would be good for v5?
What I'd like to be able to do
I'd like to be able to be able to call a function on a column from the "where" options object. I'd prefer not to use the sequelize.where function as I am building up the sql where object from multiple objects being passed in.
As an example, I have a table with a date range type column, and I'd like to be able query by the UPPER(dateRange) to see all of the past events that have ended.
I swear I tried using the sequelize.where function before, and it ended up spitting out an object instead of a sql string before. Well, sorry to have bothered you!
For anyone who runs across this same issue, here's what I did.
test.findAll({dateRange: sequelize.where(sequelize.fn("UPPER",sequelize.col("dateRange")),"<",sequelize.fn("NOW"))})// SELECT * FROM test WHERE UPPER("dateRange") < NOW();
It might be worth add this more complex use case to the "querying" section of the docs. None of the example shown in the docs (like the one below for ease of reference) indicate that you can call the sequelize.where function on a specific field inside the options object.
Post.findAll({where: sequelize.where(sequelize.fn('char_length',sequelize.col('status')),6)});// SELECT * FROM post WHERE char_length(status) = 6;
I've been trying to figure this out for 2 days, and couldn't find it anywhere in the documentation, so I think this is a feature request. I think this might require a breaking change though, so maybe it would be good for v5?
What I'd like to be able to do
I'd like to be able to be able to call a function on a column from the "where" options object. I'd prefer not to use the sequelize.where function as I am building up the sql where object from multiple objects being passed in.
As an example, I have a table with a date range type column, and I'd like to be able query by the UPPER(dateRange) to see all of the past events that have ended.
In SQL, this would be
In Sequelize, this might be something like
The text was updated successfully, but these errors were encountered: