On Mar 30, 5:39 pm, "James B. Byrne" <[email protected]> wrote:

>
> Which is why, naively, I thought that INSERT behaved the same way. I
> will take a look at the code and see what I can do in this respect.
>

I am looking at this code in activerecord-3.0.6/lib/active_record/
persistence.rb around lines 270-290.

    # Initializes the attributes array with keys matching the
    # columns from the linked table and the values matching the
    # corresponding default value of that column, so that a new
    # instance, or one populated from a passed-in Hash, still
    # has all the attributes that instances loaded from the
    # database would.
    def attributes_from_column_definition
      self.class.columns.inject({}) do |attributes, column|
        unless column.name == self.class.primary_key
          attributes[column.name] = column.default
        end
        attributes
      end
    end

And I can see two ways to proceed with this for my purposes.

I can simply put a guard condition on the column.default assignments
such that if the default value is nil/null then the attribute is not
set.  This quick, fairly innocuous, and handles my problem which is
that the pg adapter does not handle 'infinity' as a default value from
PostgreSQL and thus converts it to nil/null.

Or, I can try to map the way the update method discards unset
attributes onto the create method.   That is likely a far bigger job
but is probably more generally valuable to the community.  I will
likely take the latter course but I would like to know if any of you
have any comments or know of any considerations I should deal with
before I start.

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to