aboutsummaryrefslogtreecommitdiffstats
path: root/activestorage/app/models
diff options
context:
space:
mode:
authorRafael França <rafaelmfranca@gmail.com>2018-02-12 20:55:23 -0500
committerGitHub <noreply@github.com>2018-02-12 20:55:23 -0500
commitb9ed1fa4442633e1328dcde5a37a472b22003a6f (patch)
tree25c63154b5c693c516dba05e6369609a1072b09e /activestorage/app/models
parent2c4e9c678bcfae23fcee28c105577403ebb2aa00 (diff)
parent0c463f50eaf939042ea9561eed85146612daab5e (diff)
downloadrails-b9ed1fa4442633e1328dcde5a37a472b22003a6f.tar.gz
rails-b9ed1fa4442633e1328dcde5a37a472b22003a6f.tar.bz2
rails-b9ed1fa4442633e1328dcde5a37a472b22003a6f.zip
Merge pull request #31970 from fatkodima/active_storage-unattached-scope
Add ActiveStorage::Blob.unattached scope
Diffstat (limited to 'activestorage/app/models')
-rw-r--r--activestorage/app/models/active_storage/blob.rb2
1 files changed, 2 insertions, 0 deletions
diff --git a/activestorage/app/models/active_storage/blob.rb b/activestorage/app/models/active_storage/blob.rb
index bca9f4c590..3bcd7599d0 100644
--- a/activestorage/app/models/active_storage/blob.rb
+++ b/activestorage/app/models/active_storage/blob.rb
@@ -27,6 +27,8 @@ class ActiveStorage::Blob < ActiveRecord::Base
has_many :attachments
+ scope :unattached, -> { left_joins(:attachments).where(ActiveStorage::Attachment.table_name => { blob_id: nil }) }
+
class << self
# You can used the signed ID of a blob to refer to it on the client side without fear of tampering.
# This is particularly helpful for direct uploads where the client-side needs to refer to the blob