Skip to content
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

Fix has_many though associations when the through association is singular #49

Merged
merged 1 commit into from
Aug 22, 2024

Conversation

pi-plus-45x23
Copy link
Contributor

Attempting to reify a has_many through: association throws an error when the through: association is not has_many.

Suppose we have these associations defined:

class Post < ActiveRecord::Base
  has_one :content
  has_many :content_blocks, through: :content
end

Executing

post.versions.last.reify(has_many: true)

raises NoMethodError here if post.content is nil and here otherwise.

Wrapping the through association in an Array will fix the error. However, the given example will still produce incorrect results because we aren't reifying the content association with has_one: true. Thus, the HMT association should implicitly reify the through association regardless of the options given to reify.

@westonganger westonganger merged commit 754fcc5 into westonganger:master Aug 22, 2024
7 of 17 checks passed
@westonganger
Copy link
Owner

Merged. Thanks for your contribution!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants