allan murara

Joined

10 Experience
0 Lessons Completed
0 Questions Solved

Activity

Thank you for this material, really helpfull!
got stucked with a nested relation, i'm using rails 5.1.
i got this if i try to follow your solution > "{"players.team":["must exist"]}" the solution is to manually add a team_id to the player before call .save in rails. and after.save the current player gets the right id of the "new_team".id.

Table test :

Parameters = {"team"=>{"id"=>nil, "name"=>"testes", "players_attributes"=>[{"id"=>nil, "name"=>"dadada", "_destroy"=>false, "team_id"=>nil}]}}

controller will ignore team_id, in players_attributes as we don't intend to permit it, as long as player id and team id. assuming :

so parameters = { "team"=>{"name"=>"testes","players_attributes"=>[{"name" => "ronaldinho","position" => nil}]}}

team = new(parameters)
team.players.each do player
team.player.team_id = 1
end

team.save

and ok, it works. if i dont use this "gambiarra" each loop it will return
"{"players.team":["must exist"]}

Can you help me? thanks