Mongomapper: "SQL JOIN" style in querying
I have two models:
class TrackItem
key :state, Integer, :default => 1
many :track_jobs
end
class TrackJob
key :invoke_at, Time
belongs_to :track_item
end
I want make query with join:
item = TrackItem.create(:state => 1)
item.track_jobs.create(:invoke开发者_JS百科_at => Time.now)
TrackJob.where("track_item.state" => 1).all # => []
Return empty array. Where is problem?
MongoDB log:
MONGODB track_tweets_development['track_tweets.models.track_jobs'].find({:"track_item.state"=>1})
I'm not familiar with Ruby, but try this:
TrackItem.where(:state => 1).first.track_jobs # => should result in all specified track_jobs (so the one you created at line 2)
Since you're adding track-jobs as a embedded document, you can query the (parent) document. It'll automatically contain all your track_jobs
.
精彩评论