हमने हाल ही में रेल 4.1 से 4.2 रेल करने के लिए उन्नत और अरेल + ActiveRecord का उपयोग कर, क्योंकि हम इस प्रकार की त्रुटि हो रही है के साथ समस्याओं को देख रहे हैं:अरेल + रेल 4.2 के कारण समस्याओं (बाइंडिंग खो दिया जा रहा)
ActiveRecord::StatementInvalid: PG::ProtocolViolation: ERROR: bind message supplies 0 parameters, but prepared statement "" requires 8
यहाँ कोड है कि टूट रहा है:
customers = Customer.arel_table
ne_subquery = ImportLog.where(
importable_type: Customer.to_s,
importable_id: customers['id'],
remote_type: remote_type.to_s.singularize,
destination: 'hello'
).exists.not
first = Customer.where(ne_subquery).where(company_id: @company.id)
second = Customer.joins(:import_logs).merge(
ImportLog.where(
importable_type: Customer.to_s,
importable_id: customers['id'],
remote_type: remote_type.to_s.singularize,
status: 'pending',
destination: 'hello',
remote_id: nil
)
).where(company_id: @company.id)
Customer.from(
customers.create_table_alias(
first.union(second),
Customer.table_name
)
)
हम पता लगा क्वेरी के पहले भाग को हल करने के लिए कैसे की तरह Customer.where के भीतर होने का exists.not ले जाकर (होने बाइंडिंग नहीं की एक ही रेल बग में चल) इसलिए:
ne_subquery = ImportLog.where(
importable_type: Customer.to_s,
importable_id: customers['id'],
destination: 'hello'
)
first = Customer.where("NOT (EXISTS (#{ne_subquery.to_sql}))").where(company_id: @company.id)
यह काम करने के लिए लग रहा था, लेकिन हम कोड की इस पंक्ति के साथ एक ही मुद्दा में भाग:
first.union(second)
जब भी हम क्वेरी के इस हिस्से चलाने के लिए, बाइंडिंग खो दिया हो। पहला और दूसरा दोनों सक्रिय रिकॉर्ड ऑब्जेक्ट्स हैं, लेकिन जैसे ही हम उन्हें "संघ" करते हैं, वे बाध्यकारी खो देते हैं।
हमने क्वेरी के माध्यम से साइकिल चलाने की कोशिश की और मैन्युअल रूप से बाइंडिंग को बदल दिया लेकिन यह ठीक से काम नहीं कर सका। इसके बजाय हमें क्या करना चाहिए?
संपादित करें:
हम मैन्युअल रूप से भी पहले और दूसरे, और फिर से बाँध मान निकालने इसलिए जैसे अरेल वस्तु में उन्हें जगह करने की कोशिश की:
union.grep(Arel::Nodes::BindParam).each_with_index do |bp, i|
bv = bind_values[i]
bp.replace(Customer.connection.substitute_at(bv, i))
end
हालांकि, यह विफल रहता है क्योंकि:
NoMethodError: undefined method `replace' for #<Arel::Nodes::BindParam:0x007f8aba6cc248>
यह रेल गिथब रेपो में सुझाया गया एक समाधान था।
मुझे लगता है कि कुछ प्रश्नों को बेहतर लिखा जा सकता है (उदाहरण के लिए: दूसरा = ग्राहक। Joins (: import_logs)। कहीं (import_logs: {/ * आयात लॉग इन स्थितियां * /}) ... ... मुझे नहीं मिलता आप पूरा करने की कोशिश कर रहे हैं। – muZk