這裏是兩個表properties
和property_images
我想關聯這兩個表。紅寶石has_many模型協會不工作
性質
id
name
status
other-columns-here
property_images
id
property_id
image
status
這裏是碼 -
class Property < ActiveRecord::Base
has_many :property_images, dependent: :destroy
end
class PropertyImage < ActiveRecord::Base
belongs_to :property
end
users_controller.rb
def index
@properties = Property.order('id');
render html:@properties #13 properties coming
end
我試圖has_many
關聯,但只來了properties
數據。請幫我
您是否想要將每個屬性的屬性圖像包含在內? –
是的,我想包括has_many協會的每個財產 – Chinmay235
你實際要求的英語不清楚。我的意思是沒有進攻(我的妻子是外國人,對這個問題非常熟悉:)但也許試圖重新說明問題。上面的代碼成功「關聯」了這兩個表。我會質疑爲什麼你的「用戶」控制器中的索引顯示屬性。也許你需要使用嵌套屬性?你如何加載Property和PropertyImage數據? –