Skip to content

Commit

Permalink
fix query_constraints errors
Browse files Browse the repository at this point in the history
  • Loading branch information
smasato committed Nov 16, 2024
1 parent 9440886 commit 6f6cc7d
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 7 deletions.
4 changes: 3 additions & 1 deletion test/models/author.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# frozen_string_literal: true

class Author < ActiveRecord::Base
if ENV['AR_VERSION'].to_f >= 7.1
if ENV['AR_VERSION'].to_f >= 8.0
has_many :composite_books, foreign_key: [:id, :author_id], inverse_of: :author
elsif ENV['AR_VERSION'].to_f >= 7.1
has_many :composite_books, query_constraints: [:id, :author_id], inverse_of: :author
end
end
2 changes: 1 addition & 1 deletion test/models/book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Book < ActiveRecord::Base
belongs_to :topic, inverse_of: :books
if ENV['AR_VERSION'].to_f <= 7.0
if ENV['AR_VERSION'].to_f <= 7.0 || ENV['AR_VERSION'].to_f >= 8.0
belongs_to :tag, foreign_key: [:tag_id, :parent_id] unless ENV["SKIP_COMPOSITE_PK"]
else
belongs_to :tag, query_constraints: [:tag_id, :parent_id] unless ENV["SKIP_COMPOSITE_PK"]
Expand Down
2 changes: 1 addition & 1 deletion test/models/composite_book.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
class CompositeBook < ActiveRecord::Base
self.primary_key = %i[id author_id]
belongs_to :author
if ENV['AR_VERSION'].to_f <= 7.0
if ENV['AR_VERSION'].to_f <= 7.0 || ENV['AR_VERSION'].to_f >= 8.0
unless ENV["SKIP_COMPOSITE_PK"]
has_many :composite_chapters, inverse_of: :composite_book,
foreign_key: [:id, :author_id]
Expand Down
5 changes: 4 additions & 1 deletion test/models/composite_chapter.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
# frozen_string_literal: true

class CompositeChapter < ActiveRecord::Base
if ENV['AR_VERSION'].to_f >= 7.1
if ENV['AR_VERSION'].to_f >= 8.0
belongs_to :composite_book, inverse_of: :composite_chapters,
foreign_key: [:composite_book_id, :author_id]
elsif ENV['AR_VERSION'].to_f >= 7.1
belongs_to :composite_book, inverse_of: :composite_chapters,
query_constraints: [:composite_book_id, :author_id]
end
Expand Down
2 changes: 1 addition & 1 deletion test/models/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Customer < ActiveRecord::Base
unless ENV["SKIP_COMPOSITE_PK"]
if ENV['AR_VERSION'].to_f <= 7.0
if ENV['AR_VERSION'].to_f <= 7.0 || ENV['AR_VERSION'].to_f >= 8.0
has_many :orders,
inverse_of: :customer,
primary_key: %i(account_id id),
Expand Down
2 changes: 1 addition & 1 deletion test/models/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class Order < ActiveRecord::Base
unless ENV["SKIP_COMPOSITE_PK"]
if ENV['AR_VERSION'].to_f <= 7.0
if ENV['AR_VERSION'].to_f <= 7.0 || ENV['AR_VERSION'].to_f >= 8.0
belongs_to :customer,
inverse_of: :orders,
primary_key: %i(account_id id),
Expand Down
2 changes: 1 addition & 1 deletion test/models/tag_alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class TagAlias < ActiveRecord::Base
unless ENV["SKIP_COMPOSITE_PK"]
if ENV['AR_VERSION'].to_f <= 7.0
if ENV['AR_VERSION'].to_f <= 7.0 || ENV['AR_VERSION'].to_f >= 8.0
belongs_to :tag, foreign_key: [:tag_id, :parent_id], required: true
else
belongs_to :tag, query_constraints: [:tag_id, :parent_id], required: true
Expand Down

0 comments on commit 6f6cc7d

Please sign in to comment.