[Nitro] OG: Model#instance_attribute_set silently updates Model#new instances using WHERE oid=NULL

Mark Van De Vyver mvyver at gmail.com
Thu Aug 30 02:55:34 EDT 2007

I've been working through some examples and came across the following behavior.
I'm posting this here since there is an error page instead of the
ticket system at:

Without the '$DBG = true' setting there would be no hint that the last
statement was unsuccessful.
I'm not sure if an exception should be thrown, or the record should
just be saved (when saved? -> nil) before updating.


require 'rubygems'
require 'og'

# Full debug information.
$DBG = true

mysql_config = {
  :name => 'test',
  :store => 'mysql',
  :user => 'root',
  :password => '',

# keeping it simple
class SimplerMember
  attr_accessor :first_name, :last_name, :address1, :city, :state,
:email, String

  # define some data.
  FIXTURE = { :first_name => 'Fred', :last_name => 'Flintstone',
              :address1 => '123 High St.', :city => 'Reykjavik',
              :state => 'Michigan', :email => 'fred at flintstone.com' }

  # Initialize Og.
  mysql = Og.connect(mysql_config)

  # This will INSERT an empty row, then make an UPDATE for each
  # attribute/field using WHERE oid=<some_number>
  simmem_rec = SimplerMember.create
  FIXTURE.each { |key, value|
simmem_rec.instance_attribute_set("#{key}", value) }

  #This does an UPDATE for each field using WHERE oid=NULL
  simmem_rec = SimplerMember.new
  FIXTURE.each { |key, value|
simmem_rec.instance_attribute_set("#{key}", value) }


More information about the Nitro-general mailing list