Skip to content

Instantly share code, notes, and snippets.

@a-chernykh
Created October 9, 2015 18:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a-chernykh/b3f6b97a602d96efff22 to your computer and use it in GitHub Desktop.
Save a-chernykh/b3f6b97a602d96efff22 to your computer and use it in GitHub Desktop.
Why rails can't infer foreign key name automatically?
class Child < ActiveRecord::Base
belongs_to :parent # Child has parent_guid field
# ActiveModel::MissingAttributeError:
# can't write unknown attribute `parent_id`
end
class Parent < ActiveRecord::Base
self.primary_key = 'guid'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment