Let’s say I have two databases: one contains a list of books which are in my possession, the other contains a list of all allowed_books which are allowed by the government to be in my possession (okay, perhaps a bad example, but you’ll get the idea soon). The allowed_books database is constant and consistent. If a Book in my books database isn’t also in the allowed_books database, I need to delete it from books.
What is the best way to do this?
Is there a Rails/Sqlite function/method that will compare two databases and remove extraneous entries? Or do I have to do this somewhat manually?
I was thinking that before I actually create a new Book, I’ll run something like AllowedBook.find_by_name(book_name) on it first. If it returns nil, then I won’t add it in the first place. Or if, as stated above, Rails/Sqlite has some default way to check for inconsistencies between databases, is this a better option?
I’m fairly certain I can do it manually using find_by_name, but is this the best option?
Ruby 1.9.3, Rails 3.2.6, SQLite3 3.6.20.
Thanks!
I’m assuming that you mean “two tables”, not “two databases”. There is no way to do what you suggest in either Rails or Sqlite. You have to do it manually.