Quantcast
Channel: Active questions tagged ruby - Stack Overflow
Viewing all articles
Browse latest Browse all 4633

Rails Mongoid has_many query not using foreign_key

$
0
0

I am using mongodb for first time. I have below models

class Legacy::User  include Mongoid::Document  has_many :customers  field :username, type: Stringendclass Legacy::Customer  include Mongoid::Document  belongs_to :user  field :user_id, type: Stringend

When I run below query it doesn't return customer record.

Legacy::User.last.customers

Queries from console

{"find"=>"legacy_users", "filter"=>{}, "limit"=>1, "skip"=>0, "sort"=>{"_id"=>-1}, "$db"=>"bo_development", "lsid"=>{"id"=><BSON::Binary:0x21780 type=uuid data=0xb35d9aef1441401b...>}}{"find"=>"legacy_customers", "filter"=>{"_id"=>"zx54QQx4gPbJvQ3rm"}, "$db"=>"bo_development", "lsid"=>{"id"=><BSON::Binary:0x21780 type=uuid data=0xb35d9aef1441401b...>}}

Look at the second query, why doesn't it use user_id in filter? Am I missing something here?


Viewing all articles
Browse latest Browse all 4633

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>