[英]Rails Active record joins query
class Inquiry < ApplicationRecord
belongs_to :user , dependent: :destroy
belongs_to :booking , dependent: :destroy
end
class Booking < ApplicationRecord
belongs_to :user
belongs_to :property
has_many :inquiries
end
class Property < ApplicationRecord
belongs_to :user
has_many :bookings, dependent: :destroy
end
I have these models where a user can create a property and after that he can do a booking of that property, and after that he can create an inquiry.我有这些模型,用户可以在其中创建属性,然后他可以预订该属性,然后他可以创建查询。 On the inquiry index page I want to display a property name through the booking table in which the id property is stored.
在查询索引页面上,我想通过存储 id 属性的预订表显示一个属性名称。 Can anyone help me with that?
任何人都可以帮助我吗?
@inquiries = Inquiry.joins(booking: : property) @inquiries = Inquiry.joins(booking: : property)
This worked for me这对我有用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.