Closed adambutler closed 6 years ago
ActiveRecord's #or method requires that both sides of the query must have a compatible structure as such:
#or
User.joins(:profile).where(name: "John").or(User.where(name: "Tom")).count # => ArgumentError: Relation passed to #or must be structurally compatible. Incompatible values: [:joins] User.joins(:profile).where(name: "John").or(User.joins(:profile).where(name: "Tom")).count # => 2
The #in_state and #not_in_state methods of statesman chain the #joins and the #where calls together. This makes a query with ActiveRecord #or.
#in_state
#not_in_state
#joins
#where
For example the following would produce an error since the query does not also include the #joins
class Store < ActiveRecord::Base # ... scope :belongs_to_user, -> (user) { where(user: user) } # ... end Post.in_state(:published).or(Post.belongs_to_user(current_user))
With this change the #most_recent_transition_join method is exposed meaning that the following query could be possible resolving the issue:
#most_recent_transition_join
Post .in_state(:published) .or(Post.most_recent_transition_join.belongs_to_user(current_user))
Further instances and resources relating to this issue can be found at:
https://github.com/varvet/pundit/issues/440#issuecomment-277204775
http://codeatmorning.com/rails-5-meet-the-active-record-or-query/
ActiveRecord's
#or
method requires that both sides of the query must have a compatible structure as such:The
#in_state
and#not_in_state
methods of statesman chain the#joins
and the#where
calls together. This makes a query with ActiveRecord#or
.For example the following would produce an error since the query does not also include the
#joins
With this change the
#most_recent_transition_join
method is exposed meaning that the following query could be possible resolving the issue:Further instances and resources relating to this issue can be found at:
https://github.com/varvet/pundit/issues/440#issuecomment-277204775
http://codeatmorning.com/rails-5-meet-the-active-record-or-query/