sql = DmozCategory.send(:sanitize_sql_array, ["INSERT INTO dmoz_categories (id, dmoz_category_title, dmoz_category_name, dmoz_category_description, created_at, updated_at, dmoz_category_lastupdate) VALUES (?, ?, ?, ?, NOW(), NOW(), ?)", result['catid'], result['title'], result['name'], result['description'], result['lastupdate']]) res = DmozCategory.connection.execute(sql) $stderr.puts res.inspect
res
always nil
, although I can see that DmozCategory inserts into the database. How to get id
after my insert?
I understand that to get the identifier I could use a different SQL query SELECT LAST_INSERT_ID()
, but I was wondering if there is a way to get the identifier via Rails. M
Reference: Using Rails 2.3.14
UPDATE : Hmm, I think the problem is with the plugin that I use called Octopus . Sorry for discounting some of your answers. It looks like I need to find how to get the last insert id using this plugin. My total ratio:
desc "load all categories from dmoz" # With this one we're loading all the 'structure' table in, not the parent-child relationships. task :load_categories_from_dmoz, [ :offset, :limit ] => :environment do |t, args| offset = !args[:offset].blank? ? args[:offset].to_i : 0 # Take offset from args. Default of 0 limit = !args[:limit].blank? ? args[:limit].to_i : 1 # Take limit from args. Default of 1 ActiveRecord::Base.octopus_establish_connection(:adapter=> "mysql", :host=> "localhost", :database => "dmoz", :username => "dmoz", :password => "dmoz") results = ActiveRecord::Base.connection.select_all("SELECT * FROM structure LIMIT