Skip to content

Association with belongs_to does not work #6

Description

@makketagg

Summary

belongs_to asscociation does not work for me. I have redefined foreign_key.

Reproduce

rails ~> 5.2
pg ~> 0.21.0

# app/models/example_category.rb
class ExampleCategory < ApplicationRecord
  has_many :examples
end

# app/models/example.rb
class Example < ApplicationRecord
  belongs_to :category, class_name: 'ExampleCategory', foreign_key: :example_category_id
end
Example.reflect_on_association(:category).association_foreign_key # => 'category_id'
Example.reflect_on_association(:category).foreign_key # => example_category_id

This callout breaks getting of association data:

object.send("#{reflection.association_foreign_key}=", object.id + @id_padding)

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions