forked from zdennis/activerecord-import
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use query_constraints instead of foreign_key in relationships
- Loading branch information
Showing
5 changed files
with
17 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class Customer < ActiveRecord::Base | ||
has_many :orders, | ||
inverse_of: :customer, | ||
foreign_key: [:account_id, :customer_id], | ||
primary_key: %i(account_id id) if ENV['AR_VERSION'].to_f < 7.1 | ||
|
||
has_many :orders, | ||
inverse_of: :customer, | ||
query_constraints: [:account_id, :customer_id], | ||
primary_key: %i(account_id id) | ||
primary_key: %i(account_id id) if ENV['AR_VERSION'].to_f >= 7.0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
class Order < ActiveRecord::Base | ||
belongs_to :customer, | ||
inverse_of: :orders, | ||
foreign_key: [:account_id, :customer_id], | ||
primary_key: %i(account_id id) if ENV['AR_VERSION'].to_f < 7.1 | ||
|
||
belongs_to :customer, | ||
inverse_of: :orders, | ||
query_constraints: [:account_id, :customer_id], | ||
primary_key: %i(account_id id) | ||
primary_key: %i(account_id id) if ENV['AR_VERSION'].to_f >= 7.0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
# frozen_string_literal: true | ||
|
||
class TagAlias < ActiveRecord::Base | ||
belongs_to :tag, query_constraints: [:tag_id, :parent_id], required: true | ||
belongs_to :tag, foreign_key: [:tag_id, :parent_id], required: true if ENV['AR_VERSION'].to_f < 7.1 | ||
belongs_to :tag, query_constraints: [:tag_id, :parent_id], required: true if ENV['AR_VERSION'].to_f >= 7.0 | ||
end |