0

データマッパーに関係のないテーブルからすべてのレコードを削除するにはどうすればよいですか? 問題のテーブルは投稿とタグのテーブル (多対多の関係) であり、タグのないすべての投稿を削除したいと考えています。をしようとすると、何らかの理由Post.all(:tags => nil)で次のエラーが表示されます。

DataObjects::SyntaxError: ERROR:  operator does not exist: integer = character varying
LINE 1: ...amp", "comment_count" FROM "posts" WHERE NOT("id" IN (SELECT...
                                                             ^
HINT:  No operator matches the given name and argument type(s). You might need to add explicit type casts.
 (code: 52461700, sql state: 42883, query: SELECT "id", "timestamp", "source_network", "source_post_id", "source_user_id", "source_link", "img_full_url", "img_thumb_url", "approved", "review_timestamp", "comment_count" FROM "posts" WHERE NOT("id" IN (SELECT "tags"."name" FROM "tags" INNER JOIN "post_tags" ON "tags"."name" = "post_tags"."tag_name" INNER JOIN "posts" ON "post_tags"."post_id" = "posts"."id")) ORDER BY "id", uri: postgres:tom@localhost/hash_tagging?scheme=postgres&user=tom&password=&host=localhost&port=&path=/hash_tagging&query=&fragment=&adapter=postgres)
  from /Users/tom/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:147:in `execute_reader'
  from /Users/tom/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:147:in `block in read'
  from /Users/tom/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:276:in `with_connection'
  from /Users/tom/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/dm-do-adapter-1.2.0/lib/dm-do-adapter/adapter.rb:141:in `read'
  from /Users/tom/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/repository.rb:162:in `read'
  from /Users/tom/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/collection.rb:1117:in `lazy_load'
  from /Users/tom/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/support/lazy_array.rb:409:in `each'
  from /Users/tom/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/collection.rb:504:in `each'
  from /Users/tom/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/collection.rb:976:in `map'
  from /Users/tom/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/dm-core-1.2.0/lib/dm-core/collection.rb:976:in `inspect'
  from /Users/tom/.rbenv/versions/1.9.3-p194/bin/irb:12:in `<main>'

私が間違っていることを誰かが知っていますか?

PSタグテーブルには1つの列(キーである名前)しかなく、リレーションはdatamapperによって自動生成されたものです

4

1 に答える 1

1

NOT("id" INに変更"id" NOT IN

   DELETE FROM posts WHERE id NOT IN (SELECT id FROM tags)
于 2012-09-27T05:19:31.777 に答える