开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜