Skip to content

Commit

Permalink
Add a with_library_path scope to Attachable
Browse files Browse the repository at this point in the history
  • Loading branch information
MSchmidt authored Aug 1, 2024
1 parent e010015 commit f3f9927
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion app/models/concerns/spina/attachable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,30 @@ 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
file&.filename.to_s
end

end
end
end

0 comments on commit f3f9927

Please sign in to comment.