[英]query_as using Neo4j 5.2.3 giving nil Class
I am using neo4j 5.2.3. 我正在使用neo4j 5.2.3。 I wrote a following query in a certain method in my model
action.rb
我在模型
action.rb
中以某种方法编写了以下查询
def points_ranking
Action.query_as(:a).match('(ag:Agenda)-[a:ACTION]->(u:User)').where("a.action_type = {action_type} and a.action_allowed = {action_allowed}").params(action_type: Action::TYPE[:stance_change] , action_allowed: true ).pluck('a')
end
The following is my action.rb
以下是我的
action.rb
class Action
include Neo4j::ActiveRel
property :action_type
property :created_at, type: DateTime
property :updated_at, type: DateTime
property :deadline, type: DateTime
property :completed_at, type: DateTime
property :read_at, type: DateTime
property :expired_at, type: DateTime
##other attributes and above method
end
This gives me the following error: Undefined method query_as for nil:nilClass Action #00078eb
. 这给我以下错误:
Undefined method query_as for nil:nilClass Action #00078eb
。 Why is my Action
class nil? 为什么我的
Action
类为零? If I perform the same query on Agenda
model it returns me with results. 如果我对
Agenda
模型执行相同的查询,则会返回结果。
What am I doing wrong? 我究竟做错了什么? Any help will be much appreciated.
任何帮助都感激不尽。
I'm not sure why Action
is nil
. 我不确定为什么
Action
nil
。 I would first suggest making points_ranking
a class method and using self
instead of Action
. 我首先建议使
points_ranking
一个类方法并使用self
而不是Action
。
That said, the query_as
method isn't defined on ActiveRel
models. 也就是说,没有在
ActiveRel
模型上定义query_as
方法。 Now that you've tried it, I can see how it would be quite useful. 既然您已经尝试过,那么我可以看到它会非常有用。 I've made an issue to address this and to discuss it:
我提出了一个问题来解决这个问题并进行讨论:
https://github.com/neo4jrb/neo4j/issues/1081 https://github.com/neo4jrb/neo4j/issues/1081
If it did exist, I would think it would define the match
for you, matching on the from/to nodes as well as specifying IDs for them. 如果它确实存在,我认为这将定义
match
对你来说,在从/到节点以及配套为他们指定的ID。
For your points_ranking
method, I might implement it like this: 对于您的
points_ranking
方法,我可以这样实现:
class Agenda
include Neo4j::ActiveNode
has_many :out, :action_users, rel_class: :Action
end
class Action
def points_ranking
from_node.action_users(:u, :a)
.where_rel(action_type: Action::TYPE[:stance_change], action_allowed: true)
.pluck(:a)
end
end
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.