You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 uses public_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?
The text was updated successfully, but these errors were encountered:
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 ahas_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:I think I've traced the logic to handle the relationships all the way to this proc:
graphiti/lib/graphiti/util/serializer_relationships.rb
Line 75 in 19c75b5
public_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 checksrecords.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?
The text was updated successfully, but these errors were encountered: