How do I disassociate a record from an association without deleting the record?
Consider the following scenario, a Game
has many rules
and a rule
has many Games
so
>> game.rules #=> [#<rule id: 1, ...>, #<rule id:2, ...>]
how do I disassociate the rule of id 2 from game
without deleting it, so the relation ends up like this:
>> game.rules #=> [#<rule id: 1, ...>]
I tried reassigning an updated array to the relation, however that's preventing the association from saving future insertions somehow. I believe one can't assign arrays to relations.
This is what I've tried:
>> tmp = game.rules.to_a
>> tmp.delete(rule_of_id2)
>> game.rules = tmp
^D
but then, future insertions does not persist.
>> games.rules << new_rule_of_id3
^D
>> game.rules #=> [#<rule id: 1, ...>
It shoult return #=> [#<rule id: 1, ...>, #<rule id: 3, ...>]
how can I update the relation without explicitly deleting a rule
.