Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial
Tuomo Kankaanpää
13,574 PointsHow can I do this sql query with sequelize?
Hi!
After watching the sequelize workshop I ended up using it in my project. But now I have ran into a problem with one query. How can I make the following sql query with sequelize?
SELECT * FROM table_one AS t1 LEFT JOIN table_two as t2 ON (t1.id = t2.ref_table_one) WHERE (t1.name = "foo" AND t2.name = "bar") OR (t1.name = "bar" AND t2.name = "foo");
I dont't want to write raw sql and use sequelize.query().
I need it to be something like this:
TableOne.findAll({
include: [{
model: TableTwo,
as: 'TableTwoFk',
where: {
$or: [
{
table1.name: "foo",
table2.name: "bar"
},
{
table1.name: "bar",
table2.name: "foo"
}
]
}
}]
}).then((results)...
but I don't know how can I access the table1 name column from the include's where statement?
Any help would be much appriciated!