I'm new to MonogoDB. I've been able to seed data, but not relational stuff.
in my model I have
has_and_belongs_to_many :users
field :encrypted_password, type: String, default: ""
field :name, type: String
field :address, type: String
field :city, type: String
field :state, type: String
field :zip, type: String
In DB's like MySQL, I wouldn't use the above syntax, but instead make a migration file, pushing it to the schema. Here, in Mongo it seems more on the fly.
So with the first line (has_and...) I thought I could seed using
XYZ.create(:name => "x", {...}, user_id=>[1,2])
User.create(:name => "y", {...}, XYZ_id => [1])
This gives me a nomethod error.
Attempted to set a value for 'user_id' which is not allowed on the model XYZ.
So I added the dynamic attribues line:
include Mongoid::Attributes::Dynamic
On both the models associated models.
When I logged into the user, it didn't know the association (that particular user didn't belong to XYZ.)
Naturally I loaded up Rails C, but did not see nearly what I expected when typing
User.all (or) XYZ.all
I saw instead
2.1.0 :004 > User.all
=> #<Mongoid::Criteria
selector: {}
options: {}
class: User
embedded: false>
so I wasn't sure how to debug the issue. How can I be sure to seed the relationship appropriately?