Skip to content

Instantly share code, notes, and snippets.

@BenSchZA
Last active August 17, 2020 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenSchZA/40da2989164e755de7bac8ad278ad9a7 to your computer and use it in GitHub Desktop.
Save BenSchZA/40da2989164e755de7bac8ad278ad9a7 to your computer and use it in GitHub Desktop.
Filter by has_many association
from(record in Domain.DHR.DeviceHistoryRecord,
left_join: failures in assoc(record, :failures), on: failures.device_history_record_id == entry.id,
where: ilike(failures.type, ^"%#{query}%"),
distinct: entry.id
)
@BenSchZA
Copy link
Author

I'd like to query all DeviceHistoryRecords that have a failure of the given type. failures has a has_many/belongs_to relationship with the DeviceHistoryRecord.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment