-
-
Notifications
You must be signed in to change notification settings - Fork 910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for foreign_type #1425
Conversation
Can someone rerun those checks? Seems like a dependency / gems server was temporarily unavailable |
@mswiszcz Yup! Re-running now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @mswiszcz, sorry for the delay in reviewing this. I've left some comments below, would you mind taking another look?
@@ -1267,6 +1331,12 @@ def foreign_key_exists? | |||
!(belongs_foreign_key_missing? || has_foreign_key_missing?) | |||
end | |||
|
|||
def foreign_type_matches? | |||
return true unless options.key?(:foreign_type) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't typically return early or use the modifier form of unless
. Since the end result is a boolean, what do you think about combining these into one conditional?
!options.key?(:foreign_type) || (
!belongs_foreign_type_missing? &&
!has_foreign_type_missing?
)
@@ -1472,6 +1579,16 @@ def foreign_key_reflection | |||
end | |||
end | |||
|
|||
def foreign_type | |||
type = if [:has_one, :has_many].include?(macro) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To simplify this expression and remove the temporary assignment, what do you think about moving the .to_s
to has_column?
at line 1509?
define_model :parent do | ||
has_many :children, foreign_key: :ancestor_id, inverse_of: false | ||
end | ||
|
||
expect(Parent.new).to have_many(:children) | ||
end | ||
|
||
it 'accepts an association with a nonstandard type, with reverse association turned off' do | ||
define_model :visitor, location_id: :integer, facitility_type: :string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be facility_type
?
I think this would be a nice addition, @mswiszcz do you still plan to address the feedback? If not I can address it and give you credits. |
hey @matsales28, I totally forgot about that PR after changing project, sorry about that. Please feel free to take that over as I don't have much time at the moment to finish it |
I'm closing this PR in favor of #1609 |
Allows to create tests checking set foreign_type