Assume there's an active record model called Job which has an array column follower_ids. I have already created a scope which allows to fetch all jobs followed by a user:
# Returns all jobs followed by the specified user id
def self.followed_by(user_id)
where(
Arel::Nodes::InfixOperation.new(
'@>',
Job.arel_table[:follower_ids],
Arel.sql("ARRAY[#{user_id}]::bigint[]")
)
)
end
# Retrieve all jobs followed by user with id=1
Job.followed_by(1)
Is there a way to remove specific elements from the follower_ids column using the database (i.e., not looping through the active record objects and manually calling delete/save for each of them)?
For instance, it'd be nice to do something like Job.followed_by(1).remove_follower(1) to remove user with id=1 from all those jobs' follower_ids with just one query.