I have models:
User(id) # has_many tasks through projects
Project(id, user_id, done:boolean)
Task(project_id, done:boolean)
I’m trying to update a user’s tasks done field, but I get an ambiguous field error because both the Project and Task have a done field.
The SQL generated for marking all tasks of a user as done, is something like:
>> @user.tasks.update_all(done: true)
UPDATE tasks
INNER JOIN projects ON projects.id = tasks.project_id
SET done = 1
WHERE projects.user_id = 2548
I tried doing this:
@user.tasks.update_all("tasks.done" => true)
But that returns unknown field tasks.done which is weird as i used to specify table names on select queries and it worked.
Any idea?
Try
@user.tasks.update_all("tasks.done = 1")