① Model(Singular).joins(:② Model(Multiple))
① is User
②Schedule
Only records whose user_id and User id in the Schedule table ** match ** are acquired. Records that do not match the join condition are deleted to form one table.
Get only user column
User.joins(:schedules)
Get both columns
User.joins(:schedules).select("users.*, schedules.*")
where(Model name(Plural form):{column:value})
Is it a User model? Alternatively, you need to specify whether it is a schedule model
All the values obtained by select are changed to ** string **. In my case, because datetime was changed to a string, I couldn't use the time method, and I used time.parse to change from a string type to a date type.
This is my first post. I'm sorry that it's hard to understand. I hope it helps someone even a little.
Recommended Posts