Do have yet a way around the has many field det...
# avo-2
c
Do have yet a way around the has many field detach button issue? We're running avo 2.39 and the detach button seems to just destroy the child records.
m
Thread automatically created by Nolan in #740893011994738751
l
Hei @cold-policeman-41707 , when that happens normally is because the association is not optional, so the child record can't exist alone. If the inverse of association is configured and we can figure that out we don't even render the detach button because it will act the same as the delete, check your logs when rendering that page, are there any Avo warnings about missing configuration on the associations
inverse_of
?
c
Hi Paul, I'll check the logs, but the
inverse_of
association is definitely present. I tested with removing the dependent options and optional on the downstream
belongs_to
side, and as you mentioned, the detach button does not render, just as expected. When I add the optional option back to the
belongs_to
, it functions the same: destroys the record. Double checked my schema as well, and the reference (foreign key) is indeed nullable.
l
Some more context would be helpful to be able to reproduce it, are you able to provide some relevant parts about the relates models and them resources please?
c
Sure thing! I'll try an get some snippets this afternoon
l
Hello @cold-policeman-41707 any updates?
c
Hey sorry Paul, busy past week, I'll try and get you something by the end of the week.
f
I come with the same problem/question. Avo version 2.44 . How do we prevent records from being deleted when detaching? For example, I have User and Posts, posts belongs_to :user, optional: true; user has_many :posts, ,dependent: :nullify . In avo resources for user - field :posts, as: :has_many - and for posts - field :user, as: :belongs_to; I see detach icon in posts table and it deletes post, but I want just to nullify 🤔 what am I missing?
l
Hello @freezing-arm-94335 are you able to provide a reproduction repository?
It seems like a bug but can't reproduce it
f
At this time no. What are the conditions for record to be nullified ? It is not documented so I am not sure if I just forgot to add something else.
l
There are no avo conditions, does your DB posts column allow null on user?
f
Yes, and i have additionaly set dependent :nullify for posts in user model and optional :true for belongs_to :user in posts model
I saw you mentioned inverse_of in older message, maybe I need to add this?
l
It's important to set the
inverse_of
but if you didn't saw any logs warnings about it thats not the issue
i'm trying to reproduce it
Oh wow, i was able to reproduce it
will create an issue to track it down
thanks for reporting
c
Sorry I've been swamped the past month and haven't had much time to devote to this. Thank you for following through on this! Needless to say, I've very excited to see this PR 😂
l
No worries @cold-policeman-41707 ! I introduced the bug trying to trigger associations callbacks on detach...
c
I saw the PR! I'm excited for it to hit release 😂
l
I didn't merged it because the "delete" will not trigger callbacks
still figuring out how to keep "delete" but trigger them
c
Ah I gotcha
l
help it's welcome 😄
rails should have a way of doing it i'm just having a hard time to find it
c
Totally! I'm certainly excited for when we can get it patched up! 😄