Ignoring a relationship on specific update actions

I have an update action that toggles just a flag on a CrewMember resource. CrewMember's have many Weapons, which are set up using change manage_relationship(:weapons, type: :direct_control). I created a new update action called set_leader, which can be called in scopes of the application where the full list of Weapons is not loaded. Is there a way to set this action to not wipe out the list of Weapons when only %{ "is_leader" => true } is passed as a param?
Solution:
that's not calling your set_leader action, that's calling the update action
Jump to solution
4 Replies
sevenseacat
sevenseacat3w ago
if the set_leader action doesn't call that manage_relationship, then it won't update the weapon list
AngryBadger
AngryBadgerOP3w ago
Odd, that's what I thought, but it seems to be. I do have an after action but I don't think that's the culprit either.
FiveApps.Campaigns.CrewMember
|> Ash.Query.filter(
campaign_id == ^campaign_id and
id != ^current_crew_member.id and
is_leader == true
)
|> Ash.bulk_update!(:update, %{is_leader: false}, strategy: :stream)
FiveApps.Campaigns.CrewMember
|> Ash.Query.filter(
campaign_id == ^campaign_id and
id != ^current_crew_member.id and
is_leader == true
)
|> Ash.bulk_update!(:update, %{is_leader: false}, strategy: :stream)
Solution
sevenseacat
sevenseacat3w ago
that's not calling your set_leader action, that's calling the update action
AngryBadger
AngryBadgerOP3w ago
Oh duh! Thank you so much!

Did you find this page helpful?