我試圖從幾個表中執行連接來組合它們的列名。Rails在加入後從所有表中獲取列名
我想只是做了以下內容:
User.joins(:user_account, :user_file, :user_education).column_names
但這只是從用戶返回的列名,好像我剛剛做了以下內容:
User.column_names
有誰知道如何從連接中獲取所有列名稱?看起來這不是經常需要的,因爲似乎沒有關於它的在線信息。我需要它來驗證用戶參數。
謝謝!
編輯:在用戶表
列名:在USER_ACCOUNT表
["id", "status", "accepted_terms", "created_at", "updated_at", "email", "encrypted_password", "reset_password_token", "reset_password_sent_at", "remember_created_at", "sign_in_count", "current_sign_in_at", "last_sign_in_at", "current_sign_in_ip", "last_sign_in_ip", "confirmation_token", "confirmed_at", "confirmation_sent_at", "unconfirmed_email", "provider", "uid"]
列名:
["first_name", "last_name", "phone_number", "address"]
我希望能夠得到列名的完整列表,即
["id", "status", "accepted_terms", "created_at", "updated_at", "email", "encrypted_password", "reset_password_token", "reset_password_sent_at", "remember_created_at", "sign_in_count", "current_sign_in_at", "last_sign_in_at", "current_sign_in_ip", "last_sign_in_ip", "confirmation_token", "confirmed_at", "confirmation_sent_at", "unconfirmed_email", "provider", "uid", "first_name", "last_name", "phone_number", "address"]
我需要什麼方法才能得到完整的列表?我曾嘗試
User.joins(:user_account).column_names
但這只是給我的第一組列名,即在短短的user表中的人(不是那些在用戶帳戶表)。
您可以發佈,您有 – MZaragoza
是什麼你把我們屬於用戶列中的錯誤? – MZaragoza
是的,確切地說。 (如果有幫助,我會添加更多信息)。 – chris