Hello,
I am having a little bit problem in deleting duplicate entry of my many to
many tables.

In many to many fields delete method is deleting all the occurrence of
collection. Say I have (demo example):

class user < ActiveRecord::Base
  has_and_belongs_to_many :cars
end

class car < ActiveRecord::Base
  has_and_belongs_to_many :users
end

users and cars are many to many relationship, I have defined my
users_cars table.
Now user can have repetitive car entry as relation. For example:

Car: A,B,C User: U1,U2,U3

U1=[A,B,C,A,A,A,B]

Which can be implemented using many to many relationship, the way I have
implemented. BUT, at the time when I want to delete one of the car entries
of user the problem occurs.

Users.cars.delete(car) #deletes all occurrence of car
Users.cars.delete_at(User.cars.find_index(video_card)) #delete_at does not exist

Now how to resolve this?

I have also posted at stackoverslow (
http://stackoverflow.com/questions/31507056/deleting-first-occurrence-from-many-to-many-collection-entry-at-rails).
Please feel free to answer, and/or upvote.


Thanks.
-- 
  Md. Sadaf Noor (@sadaf2605 <https://twitter.com/sadaf2605>)
 www.sadafnoor.com

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CAAJ2eVrRTfxTbV%2BKr-dOwMPon-Q1%2BhCvTWu9e4cLJxv%2BwsN5Rw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to