avram
avram copied to clipboard
Can't bulk update from a query object with a join
Since Avram currently supports bulk updating on a query, if you add a join on to the query, it's technically a syntax error from postgres.
Soft deletes are considered bulk updates since they just update the soft_deleted_at field.
# Soft delete all comments from all posts by a specific author
CommentQuery.new.where_posts(PostQuery.new.author_id(some_author_id)).soft_delete
#=> UPDATE comments SET soft_deleted_at = $1 INNER JOIN posts ON comments.post_id = posts.id WHERE posts.author_id = $2;
Error message syntax error at or near "INNER".
I think the better way to go would be to make bulk updates work through an operation. However, we would still have to generate the proper query to know which records are being updated...
I think Lucky should reflect on the query builder, and if there are joins automatically wrap this in a subquery