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

Ruby

Nathaniel Smith
Nathaniel Smith
17,927 Points

Does any one know what I'm getting this. Mysql2::Error: Unknown column 'employees_projects.project_id' in 'where clause'

SELECT accounts.* FROM accounts INNER JOIN employees_projects ON accounts.id = employees_projects.employee_id WHERE accounts.type IN ('Employee') AND employees_projects.project_id = 1 Mysql2::Error: Unknown column 'employees_projects.project_id' in 'where clause': SELECT accounts.* FROM accounts INNER JOIN employees_projects ON accounts.id = employees_projects.employee_id WHERE accounts.type IN ('Employee') AND employees_projects.project_id = 1 ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'employees_projects.project_id' in 'where clause': SELECT accounts.* FROM accounts INNER JOIN employees_projects ON accounts.id = employees_projects.employee_id WHERE accounts.type IN ('Employee') AND employees_projects.project_id = 1

1 Answer

Brandon Barrette
Brandon Barrette
20,485 Points

Seems to be an error in one of your associations. (has_many :accounts, belongs_to :employee, etc)

The error seems to be here:

ON accounts.id = employees_projects.employee_id

Somehow the account_id is being set equal to the employee_id, which doesn't make sense. We would need to see more of your code to help you diagnose it further.