.save puts NULL in user_id field in Ruby on Rails

Posted by mathee on Stack Overflow See other posts from Stack Overflow or by mathee
Published on 2010-05-28T07:20:26Z Indexed on 2010/05/28 7:31 UTC
Read the original article Hit count: 198

Filed under:
|

Here's the model file:

class ProfileTag < ActiveRecord::Base     
  def self.create_or_update(options = {})
    id = options.delete(:id)
    record = find_by_id(id) || new
    record.id = id
    record.attributes = options
    puts "record.profile_id is"
    puts record.profile_id

    record.save!

    record
  end
end

This gives me the correct print out in my log. But it also says that there's a call to UPDATE that sets profile_id to NULL.

I'm not sure I understand why the INSERT puts the value into profile_id properly, but then it sets it to NULL on an UPDATE.

If you need more specifics, please let me know. I'm thinking that the save functionality does many things other than INSERTs into the database, but I don't know what I need to specify so that it will properly set profile_id.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord