這是不可能的,因爲它是正確的,但現在我有一個像這樣Neo4j的寶石 - 采薇多個節點/關係
events = Event.as(:e).where("((e.date_start - {current_time})/{one_day_p}) < 1 ").users(:u, :rel).where("rel.reminded = {reminded_p}").params(reminded_p: false, one_day_p: one_day, current_time: time).pluck(:e,:u, :rel)
我們的目標是獲得events
,其中起始日期小於查詢一天之外。假設我試圖採取事件,用戶和關係。我需要對每個人採取不同的行動。
我需要爲每個event
獲取所有users
,併爲每個用戶執行電子郵件操作。在該行動中,電子郵件需要訪問該event
。
接下來,我需要將rel.reminded
屬性更新爲true
。
是否有辦法同時採集所有這些以便能夠組織和執行這些任務?我開始單獨做這件事,但我必須做出額外的查詢才能實現。例如
events = Event.as(:e).where("((e.date_start - {current_time})/{one_day_p}) < 1 ").users(:u, :rel).where("rel.reminded = {reminded_p}").params(reminded_p: false, one_day_p: one_day, current_time: time).pluck(:e)
然後我不得不
events.each do |event|
# do stuff
end
# do another query that is associated and do more stuff
更新:
合併的答案,我有這樣的事情沒有清理時間的方法呢。我在一個搜索用戶的地方添加了,因爲我需要在稍後的電子郵件功能中考慮這一點。所以我不確定將它包含在查詢中比在每個用戶之外進行更有效。
@collection = Event.as(:e).where("((e.date_start - {current_time})/{one_day_p}) < 1 ").users(:u).where(setting_reminder: true).rel_where(reminded: false).params(one_day_p: one_day, current_time: time).pluck(:e, 'COLLECT(u)', 'COLLECT(rel)')
但是rel
未與此查詢一起定義。
最後回到這個。使用類似於@collection = Event.as(:e).where(「((e.date_start - {current_time})/ {one_day_p})<1」的collect方法).users(:).rel_where(提醒:false).params(one_day_p:one_day,current_time:time).pluck(:e,'COLLECT(u)','COLLECT(rel)')它不知道集合中有什麼'rel'。它說'rel沒有定義'。我添加了一個編輯,以便將其更改爲 – Clam 2014-12-17 08:50:04
'.users(:u,:rel)' – subvertallchris 2014-12-17 16:56:52
您應該可以執行')/ {one_day_p})<{one}'並將'one:1'添加到您的參數也是如此。 : -/ – subvertallchris 2014-12-17 16:57:31