Hi all, I am exploring using RoR for a new project but have run into a problem with ActiveRecord and SQL Server''s timestamp datatype. We have a NOT NULL timestamp column in a table and ActiveRecord keeps trying to update it, which promptly causes it to blow up. I have tried making the value NULL for insert and update in the model, but SQL Server doesn''t like that either. Is there any way to get ActiveRecord to just completely ignore that column short of using a view to hide it? Cheers, --Ed -------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2365 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060504/74ff9d83/smime.bin
What is the name of the column? Erik. Ed Silva schreef:> Hi all, > > I am exploring using RoR for a new project but have run into a problem > with ActiveRecord and SQL Server''s timestamp datatype. > > We have a NOT NULL timestamp column in a table and ActiveRecord keeps > trying to update it, which promptly causes it to blow up. I have tried > making the value NULL for insert and update in the model, but SQL > Server doesn''t like that either. > > Is there any way to get ActiveRecord to just completely ignore that > column short of using a view to hide it? > > Cheers, > > --Ed > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Skipped content of type multipart/alternative-------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2365 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060504/68f26604/smime.bin
The column in question is named timestamp. Cheers, --Ed On May 4, 2006, at 9:55 AM, rails-request@lists.rubyonrails.org wrote: What is the name of the column? Erik. Ed Silva schreef: Hi all, I am exploring using RoR for a new project but have run into a problem with ActiveRecord and SQL Server''s timestamp datatype. We have a NOT NULL timestamp column in a table and ActiveRecord keeps trying to update it, which promptly causes it to blow up. I have tried making the value NULL for insert and update in the model, but SQL Server doesn''t like that either. Is there any way to get ActiveRecord to just completely ignore that column short of using a view to hide it? Cheers, --Ed -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060504/7a1b0da8/attachment.html
According to the AWDWR book (page 277) only the columns created_at and created_on should be set automatically. Isn''t the problem that your trying to save the record without setting the timestamp column? You could do so in a before_create and/or before_update callback. Erik. Ed Silva schreef:> The column in question is named timestamp. > > Cheers, > > --Ed > > On May 4, 2006, at 9:55 AM, rails-request@lists.rubyonrails.org > <mailto:rails-request@lists.rubyonrails.org> wrote: > >> What is the name of the column? >> >> >> Erik. >> >> >> Ed Silva schreef: >> >>> Hi all, >>> >>> >>> I am exploring using RoR for a new project but have run into a problem >>> >>> with ActiveRecord and SQL Server''s timestamp datatype. >>> >>> >>> We have a NOT NULL timestamp column in a table and ActiveRecord keeps >>> >>> trying to update it, which promptly causes it to blow up. I have tried >>> >>> making the value NULL for insert and update in the model, but SQL >>> >>> Server doesn''t like that either. >>> >>> >>> Is there any way to get ActiveRecord to just completely ignore that >>> >>> column short of using a view to hide it? >>> >>> >>> Cheers, >>> >>> >>> --Ed >>> > > ------------------------------------------------------------------------ > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On 5/5/06, Erik van Oosten <e.vanoosten@chello.nl> wrote:> According to the AWDWR book (page 277) only the columns created_at and > created_on should be set automatically. Isn''t the problem that your > trying to save the record without setting the timestamp column? You > could do so in a before_create and/or before_update callback. >The SQL Server timestamp type is automatically updated by the server whenever the record is changed. It cannot be twiddled by client applications.
On 5/4/06, Ed Silva <ed@litmusgreen.com> wrote:> Hi all, > > I am exploring using RoR for a new project but have run into a > problem with ActiveRecord and SQL Server''s timestamp datatype. > > We have a NOT NULL timestamp column in a table and ActiveRecord keeps > trying to update it, which promptly causes it to blow up. I have > tried making the value NULL for insert and update in the model, but > SQL Server doesn''t like that either. > > Is there any way to get ActiveRecord to just completely ignore that > column short of using a view to hide it?Off the top of my head, something like this may work: class Record < ActiveRecord::Base def self.columns super.reject {|c| c.name == "timestamp"} end end Tom
This did the trick, thanks! Now I won''t have to use perl for this project! :-) Cheers, --Ed On May 5, 2006, at 8:58 AM, Tom Ward wrote:> On 5/4/06, Ed Silva <ed@litmusgreen.com> wrote: >> Hi all, >> >> I am exploring using RoR for a new project but have run into a >> problem with ActiveRecord and SQL Server''s timestamp datatype. >> >> We have a NOT NULL timestamp column in a table and ActiveRecord keeps >> trying to update it, which promptly causes it to blow up. I have >> tried making the value NULL for insert and update in the model, but >> SQL Server doesn''t like that either. >> >> Is there any way to get ActiveRecord to just completely ignore that >> column short of using a view to hide it? > > Off the top of my head, something like this may work: > > class Record < ActiveRecord::Base > def self.columns > super.reject {|c| c.name == "timestamp"} > end > end > > Tom > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails-------------- next part -------------- A non-text attachment was scrubbed... Name: smime.p7s Type: application/pkcs7-signature Size: 2365 bytes Desc: not available Url : http://wrath.rubyonrails.org/pipermail/rails/attachments/20060505/97aaf245/smime.bin