-
Type: Task
-
Resolution: Gone away
-
Priority: Major - P3
-
None
-
Affects Version/s: 7.0.4
-
Component/s: Associations
-
Labels:None
I'm experiencing some weirdness that didn't seem to be the case in ActiveRecord. Note that I'm working with a legacy database so I need to assign the foreign key on the `users` collection.
```
class User
include Mongoid::Document
include Mongoid::Timestamps
belongs_to :company, foreign_key: "companyId"
end
class Company
include Mongoid::Document
include Mongoid::Timestamps
has_many :users
end
```
Ok that all looks good to me. But when I do the following on the console, a `Company` is created, but the `User` isn't saved with the `companyId` set on it.
```
user.create_company(name: "My cool company")
```
Instead I have to add a `#save` call on `user` like so...
```
user.create_company(name: "My cool company")
user.save
```
Shouldn't `create_company` save the `User` record?