Ruby on Rails Monday, May 20, 2013

Hello,


I'm working on a rails 3 app for a legacy oracle db.  

I have a controller that saves object graphs (accepts_nested_attributes_for) but I noticed the post-update JSON response still contains the pre-update values.  

After some debugging, it appears the database connection is returning stale values (find(), reload(), etc., all return pre-update values; but SQL clients and other ActiveRecord connections find post-update values, confirming the update was written successfully to the database).

A call to ActiveRecord::Base.establish_connection fixes the problem for the 'stale' connection.

controller:

def update
  #@default_model.update_attributes(params[@model_name])
  @default_model.assign_attributes(params[@model_name])
  Graph::Helper.save(@default_model)  #custom save() for legacy version control
  
  debugger
  @default_model.some_association.updated_field   #still shows pre-update value
  @default_model.reload
  @default_model.some_association.updated_field   #still shows pre-update value
  @default_model.find(id).some_association.updated_field  #still shows pre-update value

  ActiveRecord::Base.establish_connection(:oracledb);  #THIS LINE SEEMS TO FIX THE PROBLEM.

  @default_model.reload
  @default_model.some_association.updated_field  #shows the correct, updated value.

...
end

For what it's worth, I'm using jruby in threadsafe mode with the oracle jdbc activerecord adapter.  Any suggestions on where to look to get to the bottom of the stale values?

Thanks,
Tom

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/09d612d5-f35b-4f8d-b9ca-ac214f130bc0%40googlegroups.com?hl=en-US.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments:

Post a Comment