You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to inner join a Holiday table to a HolidayDate table, then get all rows that are on dates within the array 'datesOfWeek'.
The 'Date' column is in the HolidayDate table and the 'Deleted' and 'HolidayName' column are in the Holiday table. Also the Holiday model has a has_many relationship to the HolidayDate table defined using: @has_many('IDHoliday', 'HolidayID').
Here's a bit of the code I'm writing, I believe this should be enough to replicate my issue:
Firstly, the code snippets in the description that example Orator actually should not be correct. The where clauses at the end should be based on the holiday table since it's being built on the holiday model.
My solution here is to do a few things.
Solution 1
Existing solution would be to have a where clause:
This should work fine but its not perfect. One of the issues here is that the table name is holiday_dates but that means we need to hardcode the table name.
Solution 2
The second solution here is to use a new join_on method available in the latest release which takes a single relationship and a lambda (callback) function.
This will allow you to not have to specify the table name as it will be pulled from the related methods model:
I'm trying to inner join a Holiday table to a HolidayDate table, then get all rows that are on dates within the array 'datesOfWeek'.
The 'Date' column is in the HolidayDate table and the 'Deleted' and 'HolidayName' column are in the Holiday table. Also the Holiday model has a has_many relationship to the HolidayDate table defined using: @has_many('IDHoliday', 'HolidayID').
Here's a bit of the code I'm writing, I believe this should be enough to replicate my issue:
If it helps at all when using Orator ORM I believe I had it like:
The text was updated successfully, but these errors were encountered: