diff --git a/app/models/concerns/spina/attachable.rb b/app/models/concerns/spina/attachable.rb index c7adb916d..ab99b0321 100644 --- a/app/models/concerns/spina/attachable.rb +++ b/app/models/concerns/spina/attachable.rb @@ -11,6 +11,25 @@ module Attachable "%" + Image.sanitize_sql_like(query) + "%" ) end + + scope :with_library_path, ->(query) do + folder_name, file_name = query.split("/") + unless file_name + file_name = folder_name + folder_name = nil + end + + relation = joins(:file_blob).where( + "active_storage_blobs.filename ILIKE ?", + "%" + Image.sanitize_sql_like(file_name) + "%" + ) + + if folder_name + relation.joins(:media_folder).where("spina_media_folders.name = ?", folder_name) + else + relation + end + end end def name @@ -18,4 +37,4 @@ def name end end -end \ No newline at end of file +end