instance method structurally_compatible?

Ruby on Rails edge

Since v7.0.10

Available in: v7.0.10 v7.1.6 v7.2.4 v8.0.5.1 v8.1.4 edge

Signature

structurally_compatible?(other)

Checks whether the given relation is structurally compatible with this relation, to determine if it’s possible to use the #and and #or methods without raising an error. Structurally compatible is defined as: they must be scoping the same model, and they must differ only by #where (if no #group has been defined) or #having (if a #group is present).

Post.where(id: 1).structurally_compatible?(Post.where(author_id: 3))
# => true

Post.joins(:comments).structurally_compatible?(Post.joins(:author))
# => false

Since #and and #or are focused on combining where-like clauses, a multi-value clause that this relation sets and the other one leaves unset is not counted as a difference.

Post.joins(:comments).structurally_compatible?(Post.where(id: 1))
# => true

Parameters

other req
Source
# File activerecord/lib/active_record/relation/query_methods.rb, line 1382
    def structurally_compatible?(other)
      structurally_incompatible_values_for(other).empty?
    end

Defined in activerecord/lib/active_record/relation/query_methods.rb line 1382 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::QueryMethods

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close