-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Docs
https://docs.mongodb.com/mongoid/master/tutorials/mongoid-relations/ has no mention of `primary_key`, and does mention `foreign_key` but does not explain how to use it.
I expected the following to work but it does not:
class Company include Mongoid::Document has_many :emails, primary_key: 'e', foreign_key: 'e_id' end class Email include Mongoid::Document belongs_to :company, primary_key: 'e', foreign_key: 'e_id' end
irb(main):001:0> c=Company.create!
=> #<Company _id: 5bd2015bce4ef3495e605040, >
irb(main):002:0> Email.create!(company:c)
Traceback (most recent call last):
1: from (irb):2
NoMethodError (undefined method `e' for #<Company _id: 5bd2015bce4ef3495e605040, >)
- is depended on by
-
MONGOID-4626 Querying unscoped associations ignores primary_key/foreign_key depending on association
- Closed
- is related to
-
MONGOID-4648 HABTM with foreign_key & primary_key set does not create reverse association
- Closed