0

DataMapper ドキュメントのタグ/写真の例を挙げてください。

 class Photo
   include DataMapper::Resource

   property :id, Serial

   has n, :taggings
   has n, :tags, :through => :taggings
 end

 class Tag
   include DataMapper::Resource

   property :id, Serial

   has n, :taggings
   has n, :photos, :through => :taggings
 end

 class Tagging
   include DataMapper::Resource

   belongs_to :tag,   :key => true
   belongs_to :photo, :key => true
 end

写真がないタグをすべて選択したい

Tag.select { |tag| tag.photos.size < 1}

しかし、もっと Datamapper 構文が欲しいです。何かのようなもの

Tag.all :photos.count.lt => 1  #not works

これを行う方法はありますか?高度なクエリに関する優れた Datamapper ドキュメントを知っている人はいますか? このサイトのドキュメントは非常に優れていますが、基本的すぎます。

Tkz

4

2 に答える 2

0

Tag.all(:photos => nil)2つのSQLクエリで必要なものを取得します。1つの複雑なクエリが必要な場合は、カスタムSQLを記述し、それを次のように実行する必要があります。repository(:default).adapter.select('SELECT ...')

于 2012-07-06T05:02:43.907 に答える
0

これを試して:

Tag.photos.all(:count.lt => 1)
于 2012-07-06T08:37:49.497 に答える