Search code examples
rubydatabaseormsequel

sequel check if record exists with multilpe filters


I have records of gallery with this columns:

id gallery_origin file_name ...

For records whose gallery_origin is X, I want to check whether their file_name is blank?.

I am trying to check if in column is already a present value, but just in case when is another column matched.

I think it is stupid to select all records for particular gallery_origin and check it. Maybe sequel can do this.

Some way like this?

if GalleryData.where((:gallery_origin => :id) & (:file_name => params[:file])).blank?
...

But this is not working, is there any sequel trick to do this?


Solution

  • This is solution, it works pretty well, my thinking was much more focused on sql so I tried to do AND, OR etc, but simply "," works fine.

    @Mlok Did you try GalleryData.where(:gallery_origin => id, :file_name => params[:file]).blank? – aBadAssCowboy

    Thanks