Skip to content

activerecord: Apply associations to base class' descendants - #21908

Closed
brauliobo wants to merge 1 commit into
rails:masterfrom
coletivoEITA:associations-descendants
Closed

brauliobo wants to merge 1 commit into
rails:masterfrom
coletivoEITA:associations-descendants

Conversation

@brauliobo

Copy link
Copy Markdown

currently, associations added later with freedom patching are not propagated into descendants.

@rails-bot

Copy link
Copy Markdown

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @eileencodes (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@eileencodes

Copy link
Copy Markdown
Member

Hi @brauliobo sorry for not getting around to this sooner. Can you explain more indepth why you need this? Was this broken in a certain version of Rails or is this a new bug in ActiveRecord that has existed in all versions?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you remove the extra spacing in this file so it looks like this?

require "cases/helper"
require 'models/company'

class Company
  has_many :latest_contracts, -> { order('created_at DESC') }, foreign_key: :contract_id
end

class AlwaysReflectAssociationsOnSTIBaseClassDescendants < ActiveRecord::TestCase
  def test_should_generate_valid_sql
    assert Firm.reflections.keys.include? 'latest_contracts'
  end
end

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@brauliobo
brauliobo force-pushed the associations-descendants branch from 2857243 to 879bba3 Compare October 18, 2015 23:23
@brauliobo

Copy link
Copy Markdown
Author

Hi @eileencodes! in some rails apps, you can have a model defined in some place and then extended with freedom patches elsewhere. this is the case of engines with dependencies, which is the case of my app (we call it plugins and they extend the core models).
In this situation, the sti models descendants simply won't get these new associations.

this patch fixes this.

@brauliobo

Copy link
Copy Markdown
Author

closing in favor of #24719

@brauliobo brauliobo closed this May 16, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants