我有一个应用程序,它使用 Neo4j 后端一个模型和 PostgreSQL 后端所有其他模型。这是 Neo4j 模型:
class Concept
include Neo4j::ActiveNode
property :name
def references
Reference.where(concept_uuid: uuid)
end
end
这是一个 ActiveRecord 模型。参考表上有一个 content_uuid:
class Reference < ActiveRecord::Base
def concept
Concept.where(uuid: concept_uuid).first
end
end
这行得通,我可以毫无意外地做类似Reference.first.concept
的Concept.first.references
事情。不过,我希望我可以做一些像这样简单的事情:
class Reference < ActiveRecord::Base
belongs_to :concepts
end
class Concept < ActiveRecord::Base
include Neo4j::ActiveNode
property :name
has_many :references
end
因为那样我就会得到Concept.first.references << new_reference
开箱即用的东西。是否存在这样的功能?