Activerecord sets the columns that are not specified to NULL. Postgres presumes that since your insert statement said to set the column to null you meant to set it null and ignores the default. Is there a way to tell activerecord not set missing attributes to null? Thanks. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung
2011-Aug-05 14:05 UTC
Re: postgres default values don''t work with active record
On Aug 5, 2:34 pm, Tim Uckun <timuc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Activerecord sets the columns that are not specified to NULL. Postgres > presumes that since your insert statement said to set the column to > null you meant to set it null and ignores the default. Is there a way > to tell activerecord not set missing attributes to null?I don''t think so - I think activerecord is expecting to be able to read the default values out of the database schema, although that assumes that the default is some fixed value. It should be possible to do something like this though, since updates only write unchanged columns. Fred> > Thanks.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Philip Hallstrom
2011-Aug-05 15:08 UTC
Re: postgres default values don''t work with active record
> Activerecord sets the columns that are not specified to NULL. Postgres > presumes that since your insert statement said to set the column to > null you meant to set it null and ignores the default. Is there a way > to tell activerecord not set missing attributes to null?This might be useful. https://github.com/FooBarWidget/default_value_for -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Tim Uckun
2011-Aug-05 21:51 UTC
Re: Re: postgres default values don''t work with active record
> > I don''t think so - I think activerecord is expecting to be able to > read the default values out of the database schema, although that > assumes that the default is some fixed value. > It should be possible to do something like this though, since updates > only write unchanged columns. >In postgres sometimes the default values are functions like for example UUID fields. It would work fine if it sent DEFAULT instead of NULL for the missing fields and of course it could just not mention them either. I was wondering if there is a flag somewhere in AR that says "Don''t send NULLs for missing attributes" or something. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ricardo M.
2011-Oct-19 12:04 UTC
Re: Re: postgres default values don''t work with active record
Tim Uckun wrote in post #1015220:>> >> I don''t think so - I think activerecord is expecting to be able to >> read the default values out of the database schema, although that >> assumes that the default is some fixed value. >> It should be possible to do something like this though, since updates >> only write unchanged columns. >> > > In postgres sometimes the default values are functions like for > example UUID fields. It would work fine if it sent DEFAULT instead of > NULL for the missing fields and of course it could just not mention > them either. > > I was wondering if there is a flag somewhere in AR that says "Don''t > send NULLs for missing attributes" or something.Hi, Were there any updates on this? I''m facing the same problem. Any solution? Regards -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.