ruby - Simple Rails Association causing ArgumentError -
edit: this not dupe of can't migrate after scaffold in hartl's tutorial! have arel updated in gemfile in case, makes no difference. also, post-migration, rake finished fine. after rake, when try query association via console, that when error!
i have 2 models simple one-to-many association between them. after adding second model , raking db, opened rails console test stuff out, , error every time try use association in query.
here classes:
class startup < activerecord::base has_many :reqs end class req < activerecord::base belongs_to :startup end
this migration reqs table:
class createreqs < activerecord::migration def change create_table :reqs |t| t.string :title t.text :desc t.integer :sort t.references :startup, index: true t.timestamps null: false end end end
and here simple test i'm trying test in console afterwards:
> startup = startup.first > startup.reqs ## generates argumenterror > startup.reqs.build ## generates same error
and here beginning of error:
argumenterror: wrong number of arguments (1 0) /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in `initialize' /usr/local/rvm/gems/ruby-2.1.4@rails4/gems/activerecord-4.2.0.beta4/lib/active_record/connection_adapters/abstract_adapter.rb:271:in
i'm still getting hang of lot of details of ror, please hang me! thought knew, association seems basic have no idea start fixing it. help!
i think may have been sort of fluke or bug in rails. tried again morning , rails console still giving me same error. kicks tried adding model same, different name:
class createskills < activerecord::migration def change create_table :skills |t| t.string :title t.text :desc t.integer :sort t.references :startup, index: true t.timestamps end end end
after adding has_many skills
startup.rb, went rails console , both of associations (startup.skills
, startup.reqs
) work fine. out of curiosity, did db:rollback
, destroyed skill
model , went console. startup.reqs
still works fine though skill not there anymore.
i have no idea why make difference, wanted post worked me in case else runs similar issue. try generating model kind of "reset" db , can roll , may work you.
Comments
Post a Comment