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 `foreign_key_exists?` method. #18662

Merged
merged 2 commits into from Feb 16, 2015

Conversation

Projects
None yet
5 participants
@estum
Contributor

estum commented Jan 23, 2015

No description provided.

@senny

This comment has been minimized.

Show comment
Hide comment
@senny

senny Jan 24, 2015

Member

@estum thank you for your work. Would you mind sharing some use-cases where you can see this being useful?

Member

senny commented Jan 24, 2015

@estum thank you for your work. Would you mind sharing some use-cases where you can see this being useful?

@senny senny added the activerecord label Jan 24, 2015

@senny senny added this to the 5.0.0 milestone Jan 24, 2015

@estum

This comment has been minimized.

Show comment
Hide comment
@estum

estum Jan 24, 2015

Contributor

@senny I was missing a method like index_exists? (which useful for me too) while reorganizing migrations to avoid add_foreign_key``remove_foreign_key methods raise when a key is already created\removed. I was surprised it yet hasn't been implemented.

Contributor

estum commented Jan 24, 2015

@senny I was missing a method like index_exists? (which useful for me too) while reorganizing migrations to avoid add_foreign_key``remove_foreign_key methods raise when a key is already created\removed. I was surprised it yet hasn't been implemented.

# # Check a foreign key with a custom name exists
# foreign_key_exists?(:accounts, name: "special_fk_name")
#
def foreign_key_exists?(from_table, options_or_to_table = {})

This comment has been minimized.

@ianks

ianks Jan 28, 2015

Contributor

I would consider renaming to foreign_key_exist? to avoid any confusion. For example File.exists? in Ruby is deprecated in favor of File.exist?. Should we follow that convention?

@ianks

ianks Jan 28, 2015

Contributor

I would consider renaming to foreign_key_exist? to avoid any confusion. For example File.exists? in Ruby is deprecated in favor of File.exist?. Should we follow that convention?

This comment has been minimized.

@senny

senny Jan 29, 2015

Member

I'd rather stick to the current naming:

  • index_exists?
  • table_exists?
@senny

senny Jan 29, 2015

Member

I'd rather stick to the current naming:

  • index_exists?
  • table_exists?

This comment has been minimized.

@estum

estum Jan 29, 2015

Contributor

@ianks I've been guided by the naming of similar methods (from @senny's note).

@estum

estum Jan 29, 2015

Contributor

@ianks I've been guided by the naming of similar methods (from @senny's note).

@senny senny merged commit f0ae503 into rails:master Feb 16, 2015

1 check passed

continuous-integration/travis-ci The Travis CI build passed
Details

senny added a commit that referenced this pull request Feb 16, 2015

@senny

This comment has been minimized.

Show comment
Hide comment
@senny

senny Feb 16, 2015

Member

@estum great work! 💛

I added a CHANGELOG entry and made some minor changes in the merge commit (removed trailing whitespace, replaced all?{|assoc|} with all? {|key, value|} and got rid of try(:name).

The extraction of foreign_key_for already paid off. Merging this I found a bug in a recent patch I committed (8980da8).

Member

senny commented Feb 16, 2015

@estum great work! 💛

I added a CHANGELOG entry and made some minor changes in the merge commit (removed trailing whitespace, replaced all?{|assoc|} with all? {|key, value|} and got rid of try(:name).

The extraction of foreign_key_for already paid off. Merging this I found a bug in a recent patch I committed (8980da8).

@@ -650,6 +658,10 @@ def remove_references(*args)
def foreign_key(*args) # :nodoc:
@base.add_foreign_key(name, *args)
end
def foreign_key_exists?(*args) # :nodoc:

This comment has been minimized.

@claudiob

claudiob Feb 20, 2015

Member

@senny Is this # :nodoc: intentional? Or should we make this method publicly documented?

@claudiob

claudiob Feb 20, 2015

Member

@senny Is this # :nodoc: intentional? Or should we make this method publicly documented?

This comment has been minimized.

@senny

senny Feb 23, 2015

Member

@claudiob I think it was due to the fact that foreign_key had a no-doc as well. It was previously only used by references. Should be fine to document them though.

@senny

senny Feb 23, 2015

Member

@claudiob I think it was due to the fact that foreign_key had a no-doc as well. It was previously only used by references. Should be fine to document them though.

@rafaelfranca rafaelfranca modified the milestones: 5.0.0 [temp], 5.0.0 Dec 30, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment