Open
Description
Hello, please correct me if I am wrong with my assumptions here.
My use-case is that I'd like to use has_one
with a has_one_attached
object. The issue is that the method on the model always returns this non-nil "proxy" object even when nothing is attached. For example:
class User
has_one_attached :avatar
end
> User.new.avatar
#<ActiveStorage::Attached::One...
I think I've traced the logic to handle the relationships all the way to this proc:
-- it simply usespublic_send
to call the association method which leads to issues down the line when a non-nil object is returned but is not backed by any data.
Unfortunately, I did not see a great way to resolve this without overriding the entire data_proc
method with a monkey-patch that checks records.attached?
and returns nil accordingly.
Is there a built-in way to do this I don't know about, and if not, what would be the preferred approach to allow for custom associations such as this?
Metadata
Metadata
Assignees
Labels
No labels