Hi, I''ve used .save to save the attributes, but on my table there is an autoincrementing id (not the primary key) that doesn''t need to be inserted... but save try to INSERT it anyway... is there a way to avoid save from acting this way or to whisper him to be more polite this time? ;) Thanks, Enrico -- "The only thing necessary for the triumph of evil is for good men to do nothing" Edmund Burke
On Mon, 7 Mar 2005 17:08:01 +0100, Enrico Teotti <agenteo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > I''ve used .save to save the attributes, but on my table there is an > autoincrementing id (not the primary key) that doesn''t need to be > inserted... but save try to INSERT it anyway... is there a way to > avoid save from acting this way or to whisper him to be more polite > this time? ;) > Thanks, > Enrico >I just read this over at http://wiki.rubyonrails.com/rails/show/HowtoUsePostgresViewsAsTables . I havent tried it, just read it minutes before seeing your mail. Raph Active Record doesn''t have support for making columns read-only, but you can simulate the effect by using attr_protected and defining empty writer methods: require ''active_record'' class Quote < ActiveRecord::Base attr_protected :score, :votes, :activity def score=(ignored) end def votes=(ignored) end def activity=(ignored) end end> -- > "The only thing necessary for the triumph of evil > is for good men to do nothing" > Edmund Burke > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
I''ve tried without luck this solution... I''ve still got the error on the .save method... telling the column violates not-null constraint. It''s still trying to insert that column on the save call. Someone else has tried this solution on a problem like mine? Thanks On Mon, 7 Mar 2005 17:13:57 +0100, Raphael Bauduin <rblists-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mon, 7 Mar 2005 17:08:01 +0100, Enrico Teotti <agenteo-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Hi, > > I''ve used .save to save the attributes, but on my table there is an > > autoincrementing id (not the primary key) that doesn''t need to be > > inserted... but save try to INSERT it anyway... is there a way to > > avoid save from acting this way or to whisper him to be more polite > > this time? ;) > > Thanks, > > Enrico > > > > I just read this over at > http://wiki.rubyonrails.com/rails/show/HowtoUsePostgresViewsAsTables . > > I havent tried it, just read it minutes before seeing your mail. > > Raph > > Active Record doesn''t have support for making columns read-only, but > you can simulate the effect by using attr_protected and defining empty > writer methods: > > require ''active_record'' > > class Quote < ActiveRecord::Base > attr_protected :score, :votes, :activity > def score=(ignored) end > def votes=(ignored) end > def activity=(ignored) end > end > > > -- > > "The only thing necessary for the triumph of evil > > is for good men to do nothing" > > Edmund Burke > > _______________________________________________ > > Rails mailing list > > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > >-- "The only thing necessary for the triumph of evil is for good men to do nothing" Edmund Burke
Enrico Teotti wrote:> I''ve tried without luck this solution... I''ve still got the error on > the .save method... telling the column violates not-null constraint. > It''s still trying to insert that column on the save call. > Someone else has tried this solution on a problem like mine? > ThanksMaybe that''s overkill, but you could override the columns_hash method, which both create and update rely internatlly, to never include the problematic column.