我有继承
的电子邮件模型class Email
def self.email_types
{
welcome_email: EmailWelcome,
ban_email: EmailBan
}
end
def self.create_new(params)
klass = Object.const_get(params[:type].to_s)
klass.new(params)
end
end
class EmailBan < Email
end
class EmailWelcome < Email
end
Email
类是抽象的。这些类是通过Email.create_new
创建的,其类型与具体类相匹配。
如果我输入Email.count
它会计算所有EmailWelcome
和EmailBan
。这就是我想要的,所以我可以通过Email.all
列出所有电子邮件。
但有时在尝试迭代或调用Email.first
时会出现以下错误。
irb(main):138:0> Email.last
ArgumentError: comparison of Class with Class failed
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-4.1.5/lib/neo4j/active_node/node_wrapper.rb:34:in `sort'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-4.1.5/lib/neo4j/active_node/node_wrapper.rb:34:in `sorted_wrapper_classes'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-4.1.5/lib/neo4j/active_node/node_wrapper.rb:7:in `wrapper'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:86:in `hash_value_as_object'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:68:in `map_row_value'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:58:in `block (3 levels) in to_node_enumeration'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:57:in `each_pair'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:57:in `each_with_object'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:57:in `block (2 levels) in to_node_enumeration'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:43:in `block in each'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:140:in `block in each_data_row'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:140:in `each'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:140:in `each_data_row'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:40:in `each'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-server/cypher_response.rb:55:in `block in to_node_enumeration'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-core/query.rb:176:in `each'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-core/query.rb:176:in `each'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-core/query.rb:176:in `each'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-core/query.rb:212:in `map'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-core-4.0.7/lib/neo4j-core/query.rb:212:in `pluck'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/neo4j-4.1.5/lib/neo4j/active_node/query_methods.rb:20:in `last'
from (irb):138
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:110:in `start'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/console.rb:9:in `start'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:68:in `console'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands/commands_tasks.rb:39:in `run_command!'
from /Users/perich/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/railties-4.2.4/lib/rails/commands.rb:17:in `<top (required)>'
from bin/rails:4:in `require'