Fails on Rails 5.0.0.beta3: undefined method `visitor' for ActiveRecord::Relation
glebm opened this issue · comments
https://travis-ci.org/thredded/thredded/jobs/121828657
Failure/Error: [search_topics, search_posts].compact.reduce(:union)
NoMethodError:
undefined method `visitor' for #<ActiveRecord::Relation []>
# gems/activerecord-5.0.0.beta3/lib/active_record/relation/delegation.rb:124:in `method_missing'
# gems/activerecord-5.0.0.beta3/lib/active_record/relation/delegation.rb:94:in `method_missing'
# gems/active_record_union-1.1.1/lib/active_record_union/active_record/relation/union.rb:31:in `set_operation'
# gems/active_record_union-1.1.1/lib/active_record_union/active_record/relation/union.rb:11:in `union'
# ./lib/thredded/topics_search.rb:17:in `each'
# ./lib/thredded/topics_search.rb:17:in `reduce'
# ./lib/thredded/topics_search.rb:17:in `search'
# ./app/models/thredded/topic.rb:12:in `block in <class:Topic>'
# gems/activerecord-5.0.0.beta3/lib/active_record/scoping/named.rb:159:in `instance_exec'
# gems/activerecord-5.0.0.beta3/lib/active_record/scoping/named.rb:159:in `block (2 levels) in scope'
# gems/activerecord-5.0.0.beta3/lib/active_record/relation.rb:351:in `scoping'
# gems/activerecord-5.0.0.beta3/lib/active_record/scoping/named.rb:159:in `block in scope'
# ./spec/models/thredded/topic_spec.rb:67:in `block (2 levels) in <module:Thredded>'
After replacing the call to visitor
with connection.visitor
in union.rb:31, I get another error:
Failure/Error: topics.map { |topic| new(user, topic) }
ActiveRecord::StatementInvalid:
SQLite3::MismatchException: datatype mismatch: SELECT "thredded_topics".* FROM ( SELECT "thredded_topics".* FROM "thredded_topics" WHERE "thredded_topics"."messageboard_id" = ? AND ("thredded_topics"."title" COLLATE NOCASE LIKE '%rando%') AND ("thredded_topics"."title" COLLATE NOCASE LIKE '%thread%') UNION SELECT "thredded_topics".* FROM "thredded_topics" INNER JOIN "thredded_posts" ON "thredded_posts"."postable_id" = "thredded_topics"."id" WHERE "thredded_topics"."messageboard_id" = ? AND ("thredded_posts"."content" COLLATE NOCASE LIKE '%rando%') AND ("thredded_posts"."content" COLLATE NOCASE LIKE '%thread%') ) "thredded_topics" ORDER BY "thredded_topics"."updated_at" DESC, "thredded_topics"."id" DESC LIMIT ? OFFSET ?
@brianhempel I've improved the test harness in #10 to help with fixing this and making sure it doesn't break in the future.
Added support for Rails 5 in #10.
Thanks 👍