you are here: codestackercodes [RSS] → tag activerecord [RSS]

activerecord without rails

require 'active_record'

ActiveRecord::Base.establish_connection(:adapter => 'mysql2', :host => 'localhost', :user => 'root', :password => 'mypass', :database => 'mydatabase')

class User < ActiveRecord::Base ; end

puts User.count
#=> 9

finding duplicates entries

having example in rails. from: http://blog.grayproductions.net/articles/five_activerecord_tips

duplicates = User.find( :all,
  :select     => "email, COUNT(email) AS duplicate_count",
  :conditions => "email IS NOT NULL AND email != ''",
  :group      => "email HAVING duplicate_count > 1"
)
Displaying all 2 Code