4 ms·
Sequel's syntax is strictly less powerful, since Rails' accepts any scope instead of just a hash of conditions. Post.where(id: 1).or Post.joins(:author).wh
by stouset 10y ago
Sequel's syntax is strictly less powerful, since Rails' accepts any scope instead of just a hash of conditions.
Post.where(id: 1).or Post.joins(:author).where(author: { name: 'John' })
- cyberferret 10y agoCorrect me if I am wrong, but can't the Sequel ORM accomplish this as well? Post.join(:author).where(:author__name => "John") (the above is purely from memory and may have syntax errors). In any case, it lets you drop into raw SQL as a last resort.
- cortesoft 10y agoYes, you are correct.
- jeremyevans 10y agoThat doesn't appear to work: Post.where(id: 1).or Post.joins(:author).where(author: { name: 'John' }) ArgumentError: Relation passed to #or must be structurally compatible. Incompatible values: [:joins, :references] It appears that only the filter clauses are allowed to be different (similar errors if :select, :order, :group, :limit are different), in which case it's no more powerful than Sequel, just more of a pain to use. You can easily implement ActiveRecord's behavior in Sequel if you want to combine filter clauses for arbitrary datasets: ds = Post.where(id: 2) Post.where(id: 1).or(ds.opts[:where]) It's also interesting what happens if you mix where and having clauses (I'm not saying it doesn't make sense, but it may bite someone): Post.where(id: 1).or(Post.having(id: 2)).to_sql # SELECT "posts".* FROM "posts"