2015-04-27 52 views
0
McEntity.joins(:member_credit_scores).includes(member_credit_ent_profile: :entity).where('sf.accountx.namex like ?', "% Time%").first 

以上是我的查詢。我期待的是寫入包含在rails4中的嵌套查詢

mc_entity = { 
    entity_sf_account_id: '0014PRD000fkeejAAA', 
    license_date: Date.today, portfolio_type_id: @portfolio_type.id, 
    technology_description: "some technology_description", is_rejected: false, credit_value_rating_type_id: @credit_rating_type.id, 
    member_credit_scores: { 
     "0" => { 
     avoided_expense: 151515, likelihood_of_assertion: 15, avoided_expense_notes: "some expense notes", 
     likelihood_notes: "some likelihood notes", is_approved: true 
     }, 
     "1" => { 
     avoided_expense: 303030, likelihood_of_assertion: 30, avoided_expense_notes: "some random expense notes", 
     likelihood_notes: "some random likelihood notes", is_approved: false 
     } 
    } 
    } 

但是我得到的是McEntity與沒有任何關係的數據。

mc_entity = { 
    entity_sf_account_id: '0014PRD000fkeejAAA', 
    license_date: Date.today, portfolio_type_id: @portfolio_type.id, 
    technology_description: "some technology_description", is_rejected: false, credit_value_rating_type_id: @credit_rating_type.id, 

    } 
+0

您是否對您的結果對象試過'to_json'? – RAJ

+0

是的,它沒有關係數據,但急切的加載正在工作,因爲當我檢索子記錄時它不會再次寫查詢 – santosh

+0

你可以添加它的問題,它看起來像嗎? – RAJ

回答

1

的數據實際上是被拉到,如果調用#member_credit_scores方法將返回數據,不進行查詢的,如果你想要的JSON裏面,那麼你可以傳遞作爲參數

entity.to_json(methods: member_credit_scores) 

這將調用該方法並將其添加到json對象。