我有两个表格方向和注册,我想执行一个加入查询。这里是每个表的模式...Mysql加入导轨
create_table "orientations", :force => true do |t|
t.date "class_date"
t.text "class_time"
t.integer "seats"
t.boolean "active", :default => true
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
create_table "registrations", :force => true do |t|
t.integer "orientation_id"
t.string "first_name"
t.string "last_name"
t.string "email"
t.string "student_id"
t.string "phone"
t.string "registration_cancellation_token"
t.datetime "registration_cancelled_at"
t.boolean "checked_in", :default => false
t.boolean "cancelled", :default => false
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
t.text "program"
end
我在找的是所有的方向在两个日期之间的所有注册。我想出了这个...
Registration.where(Orientation.where created_at: => @[email protected]_date)
当然,这种语法是假的,但很快它将有助于获得我所期待的。
Registration.includes([:方向]),其中(”。 orientation.created_at在?和?之间,@start_date,@end_date)...试试这个,让我知道 – userRandom