Feng Tien
2008-Feb-22 01:26 UTC
checking for duplicates, if duplicate, concate duplicate...
Here''s the break down. 2 models: song, artist artists has many songs. Is there already a pre-built method in rails that can check for duplicate artists, and if the artist already exists, it will add the song object instead of creating a new artist? If there isn''t I can write the method, would you write this in the model or the controller? Basically it would do this. grabs the artist[:name] params, do a find_by_name, if it finds it, then it will do concate with the song object, otherwise, it would create a new artist id. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Alain Ravet
2008-Feb-22 12:05 UTC
Re: checking for duplicates, if duplicate, concate duplicate...
Feng Tien, > grabs the artist[:name] params, do a find_by_name, if it finds it, then > ..., otherwise, it would create a new artist id. try : a = Artist.find_or_create_by_name(params[:name]) Alain --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---