lib/architect4r/model/queries.rb in architect4r-0.3.4.2 vs lib/architect4r/model/queries.rb in architect4r-0.4
- old
+ new
@@ -12,10 +12,12 @@
def count(opts = {}, &block)
data = connection.execute_cypher("start s=node(#{self.model_root.id}) match (s)<-[:model_type]-(d) return count(d)")
data['data'].flatten.first
end
+ # Fetch a record of the specified model based on its id
+ #
def find_by_id(id)
data = connection.execute_cypher("start s=node(#{self.model_root.id}), d=node(#{id.to_i}) match s<-[r:model_type]-d return d")
data &&= data['data'] && data['data'].flatten.first
self.build_from_database(data)
end
@@ -30,9 +32,13 @@
result_data = connection.transform_cypher_result_to_hash(result_data)
result_data.map { |item| connection.convert_if_possible(item[identifier]) }
else
nil
end
+ end
+
+ def all
+ find_by_cypher("start ModelRoot=node(#{self.model_root.id}) match ModelRoot<-[:model_type]-Item return Item", 'Item')
end
end
end
end
\ No newline at end of file