DataMapperのdefault_scopeのマージされ方がおかしい。

class Entry
  default_scope(:default).update(:draft => false)
end
>> Entry.count
SQL: (0.000099) SELECT COUNT(*) FROM "entries" WHERE ("draft" = 'f'))
=> 1
>> Entry.count(:draft => true)
SQL: (0.000099) SELECT COUNT(*) FROM "entries" WHERE ("draft" = 'f' AND "draft" = 't')
=> 0

ActiveRecordでも多用していた機能なので困ったなと思ってたら・・・。

#1202 Overwriting default_scope conditions is broken - DataMapper - datamapper

It's a private API so the ticket should be treated more like a suggestion to make the default_scope a public method and of course make it work correctly.

default_scopeはprivate APIなのでbugではなくsuggestion扱いだそうです。ticketのstateもholdになってました・・・。

tikushoo

Comments


Option