I do not know why my previous post was deleted. I am trying again. In Firebird database one can declare computed columns. These columns are readonly in the database. How do I stop activerecord to include these columns in insert statements when creating a record? I know about attr_readonly which works fine when updating. -- 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.
I hope attr_accessor can work for this purpose. It wont be inserted in db. On Fri, Apr 16, 2010 at 10:13 AM, john <john-eRg+Z95SD7IQZ7m9OUuf1w@public.gmane.org> wrote:> I do not know why my previous post was deleted. I am trying again. > > In Firebird database one can declare computed columns. These columns > are readonly in the database. How do I stop activerecord to include > these columns in insert statements when creating a record? > > I know about attr_readonly which works fine when updating. > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- 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.
Can you please explain this? I do not see anything about attr_accessor in the activerecord api. Thanks Op 16/04/2010 07:14, K.Arunmohan het geskryf:> I hope attr_accessor can work for this purpose. It wont be inserted in db. > > On Fri, Apr 16, 2010 at 10:13 AM, john <john-eRg+Z95SD7IQZ7m9OUuf1w@public.gmane.org > <mailto:john-eRg+Z95SD7IQZ7m9OUuf1w@public.gmane.org>> wrote: > > I do not know why my previous post was deleted. I am trying again. > > In Firebird database one can declare computed columns. These columns > are readonly in the database. How do I stop activerecord to include > these columns in insert statements when creating a record? > > I know about attr_readonly which works fine when updating. > > -- > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > <mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > <mailto:rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > 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.-- 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.
K.Arunmohan probably means attr_accessible and not attr_accessor. attr_accessor is a ruby function that generates instance variables and getters/setters for these. If you use attr_protected it will prevent the attributes from being set through mass-assignment, and you would spesifically need to use object.attribute = ''value'' to set it. The value will not be removed from the SQL though, like it does during updates when you use attr_readonly, it will be set to nil. If this is not good enough you willl need to remove the attibute manually from the object before you create it. before_create(:remove_attribute) private def remove_attribute @attributes.delete(''unwanted_attribute'') end Beware that this removes the attribute completly from the current object. If you need to access the removed attribute after having created the record, the record will need to be reloaded. On Apr 16, 7:58 am, John le Roux <j...-eRg+Z95SD7IQZ7m9OUuf1w@public.gmane.org> wrote:> Can you please explain this? I do not see anything about attr_accessor > in the activerecord api. > > Thanks > > Op 16/04/2010 07:14, K.Arunmohan het geskryf: > > > > > I hope attr_accessor can work for this purpose. It wont be inserted in db. > > > On Fri, Apr 16, 2010 at 10:13 AM, john <j...-eRg+Z95SD7IQZ7m9OUuf1w@public.gmane.org > > <mailto:j...-eRg+Z95SD7IQZ7m9OUuf1w@public.gmane.org>> wrote: > > > I do not know why my previous post was deleted. I am trying again. > > > In Firebird database one can declare computed columns. These columns > > are readonly in the database. How do I stop activerecord to include > > these columns in insert statements when creating a record? > > > I know about attr_readonly which works fine when updating. > > > -- > > 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > <mailto:rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > > To unsubscribe from this group, send email to > > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org > > <mailto:rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org>. > > For more options, visit this group at > > http://groups.google.com/group/rubyonrails-talk?hl=en. > > > -- > > 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. > > -- > 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 athttp://groups.google.com/group/rubyonrails-talk?hl=en.-- 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.