簡體   English   中英

ActiveRecord,選擇查詢數組返回ImportsController#index中的ActiveRecord :: StatementInvalid

[英]ActiveRecord, select query for an Array returns ActiveRecord::StatementInvalid in ImportsController#index

我有一個自定義列表,該列表是從“后台”創建的,在其中添加了我想從數據庫表中檢索的列。 這將成為一個數組。 好吧,我只想從與ID匹配的行中檢索該列。

這是我的代碼:

def load_import_contacts
    @import_contacts_column_filter = current_user.current_organization.import_columns.split(/,/) # the "custom filter" that retrieve columns
    @import_contacts = UserImport.select(@import_contacts_column_filter).where(organization_id: current_user.current_organization.id) # the query
    # here all ok, objects filtered how i want.
    @import_contacts_listing = smart_listing_create(
      # here comes the error message
      :import_contacts,
      @import_contacts,
      partial: 'contacts/listing_import',
      default_sort: {created_at: "desc"}
    )
  end

錯誤信息:

標題

ActiveRecord::StatementInvalid in ImportsController#index 

正文訊息

Mysql2::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' name, surname1, surname2, phone, adress, city, zipcode, zone, birthdate, firstv' at line 1: SELECT COUNT(reference_number, name, surname1, surname2, phone, adress, city, zipcode, zone, birthdate, firstvisit, mutua, organization_id) FROM `user_imports` WHERE `user_imports`.`organization_id` = 279

更多細節

Extracted source (around line #15): 

第15行:

@import_contacts_listing = smart_listing_create(

奇怪的解決方案

當我在智能列表之前添加此行時

**@import_contacts.each do |before|
end**

一切運行正常,這很奇怪,我不知道為什么會這樣。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM