Scope for records with derivatives

Hi guys, I was wondering what would be the cleanest way to create a scope to filter records that have derivates completed? I’m currently creating the derivatives asynchronously and so to make the records visible publicly I would like to be able to filter to only have the one who have their derivatives completed.

Thank you!

Hi, you can check for presence of the derivatives key, which should only exist if there are some derivatives created. Example query:

SELECT * FROM photos
WHERE image_data IS NOT NULL AND image_data::jsonb ? 'derivatives'

Nice thank you Janko! Would that means all derivatives are complete or only some of them could be complete?

Derivatives are persisted only once they’ve all been generated. It’s possible to generate different derivatives at different times, but that can only be done manually (so you’d know if that’s the case in your app :slightly_smiling_face:).

That makes sense! Yep! Thanks again.