I have a habtm relationship (assignments < assignments_candidates > candidates)
I want to be able to delete one candidate off an assignment. here is my code so far
@assignment = Assignment.find(:first,
:joins => :candidates,
:select => "assignments_candidates.*",
:conditions => ["assignments_candidates.candidate_id = ? AND assignments_candidates.assignment_id = ?",
params[:candidate_id], params[:assignment_id]]
)
@assignment.destroy
At the moment all i think this does is destroy the object not the record in the intersection table
any ideas ?
Thanks, Alex
Here is how I did it for future reference.
assignment = Assignment.find(params[:assignment_id])
candidate = assignment.candidates.find(params[:candidate_ids])
assignment.candidates.delete(candidate)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With