From: Derek Cannon Date: 2010-03-30T17:38:52+09:00 Subject: Re: Fastest Array Search? > Primary keys and unique indexes in the database ensure that you don't > have duplicated rows. > Are you using ActiveRecord? I don't even know what that means yet. I just started with Rails a few days ago. I just created a project, created a database with the fields I want, and used scaffold. I can add/edit/delete elements of my database, that's pretty much all. I've already written a class that will parse XML files for data, load that data into an array of instantiated classes called "Movie". For example, each Movie class has a title, rating, plot, etc. I just want to make sure the movie's title and release date don't already exist in a database before I add them. For example, I was thinking of something like this: # @movie_db is the Rails SQLite3 database # @movies holds the temporary array of all the Movie classes, #each which have many variables: title, rating, plot, etc @movies.each { |i| if @movie_db.find { |x| (x["title"] == i.title) and x["release_year"] == x.release_year } == false @movie_db = MovieDb.new("title"=>i.title,"plot"=>i.plot,etc) @movie_db.save end end ^ This is just the basic code. It makes sure @movies elements will only be added if a movie is unique (based on title and release date (since there are some movies with the same name, but none that I can think of with the same name AND release year)). -- Posted via http://www.ruby-forum.com/.