Posted By

abstraktor on 04/17/11


Tagged

relations rails3


Versions (?)

remove duplicates from Relations


 / Published in: Rails
 

Remove all duplicate Adresses from first User.

  1. #app/models/user.rb
  2. class User < ActiveRecord::Base
  3. has_many :adresses
  4. end
  5.  
  6. #app/models/adress.rb
  7. class Adress < ActiveRecord::Base
  8. belongs_to :user
  9. end
  10.  
  11. #irb
  12. User.first.adresses.map do |address|
  13. if liste.include? address
  14. address.destroy
  15. else
  16. liste.push address
  17. end
  18. end

Report this snippet  

You need to login to post a comment.