activerecord, created_on column

aaronsmith wrote:

hey everyone, having some weird experiences when creating a new record with active record..

doesn't active_record automagically handle created_on and updated_on coloumns? I keep getting errors::

ArgumentError: wrong number of arguments (1 for 0)     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:328:in `notify'     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:328:in `callback'     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/callbacks.rb:295:in `valid?'     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:751:in `save_without_transactions'     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save'     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/connection_adapters/abstract/database_statements.rb:59:in `transaction'     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:95:in `transaction'     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:121:in `transaction'     /usr/local/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/transactions.rb:129:in `save'     ./test/unit/user_test.rb:46:in `test_create_user'

I understand what the error is saying about wrong arguments.. but none of my methods are using any arguments.. Here is the test script i've written to test i..

require 'rubygems' require 'active_record'

class Users < ActiveRecord::Base end

class T   def initialize     ActiveRecord::Base.establish_connection(       :adapter => "mysql",       :host => "localhost",       :username => "root",       :password => "",       :database => "something_dev"     )   end

  def ctest     @nu = Users.new({       :user_name => 'davidh',       :first_name => 'david',       :last_name => 'hasselhoffenmeier',       :phone => '34928293',       :email => 'adasdf@asdfasdf.com',       :company => 'whatever',       :user_type => 0,       :notify => 0})     @nu.save   end end

@r = T.new @r.ctest

--my table has a created_on column as a date type, and I get the above errors when running this script.. any ideas?

thanks all

Not sure if this helps, but I think created_on needs to be a timestamp not a date.. Cheers Mohit.

aaronsmith wrote:

Not sure if this helps, but I think created_on needs to be a timestamp not a date.. Cheers Mohit.      Shoot - that didn't seem to help any.. it seems like there is actually a bigger problem. As I have taken out the created_on column, and now when I run my unit tests I still get that error..

Is there anything that migrations do specifically to a database to be active record friendly? As I have not been using migrations.. just using navicat and hacking away.

I think the only main difference is that they will by default create an auto-increment field called 'id' that serves as the primary key. Are you creating one?

Cheers Mohit.

aaronsmith wrote:

Mohit Sindhwani wrote:   

aaronsmith wrote:     

Is there anything that migrations do specifically to a database to be active record friendly? As I have not been using migrations.. just using navicat and hacking away.

I think the only main difference is that they will by default create an auto-increment field called 'id' that serves as the primary key. Are you creating one?

Cheers Mohit.      yes.. and actually.. the only time this is happening is when i've got a created_on column in the database. I've tried numerous different data types (date, datetime, timestamp).. when using ActiveRecord by itself it didn't matter.. but now when tying it through rails.. it just fails all together..

sorry, I'm at wits' ends here - haven't experienced this issue at all. I do hope that someone else replies to the thread :-S

Cheers Mohit.

This feels like a red-herring.

try to create a simple project that replicates the problem.

I suspect that in your current project something else is triggering this happen - a plugin, a callback.

Cheers, Jodi General Partner The nNovation Group inc. www.nnovation.ca/blog

on-innovation.gif

aaronsmith wrote:

Mohit Sindhwani wrote:   

aaronsmith wrote:     

I think the only main difference is that they will by default create an         

didn't matter.. but now when tying it through rails.. it just fails all together..

sorry, I'm at wits' ends here - haven't experienced this issue at all. I do hope that someone else replies to the thread :-S

Cheers Mohit.      AHH.. I got it.. one of my colum names was 'notify', and apparently active_record doesn't like that. there must be a notify method on active_record.

-A

Good to know that, phew! Cheers Mohit.