ruby on rails 3 - Why doesnt a migration update a model? -


i'm new rails , trying understand relationship between migrations , models. far can tell migration seems affect datastore hence after use scaffolding create resource, responsible keeping model , migrations in sync? there tools assist in this?

sorry if obvious question, i'm still working way through docs.

all migrations modify database. rails handles maintaining sync between model , database.

you can have user table has id, firs_name , class model might this

class user < activerecord::base end 

as can see model class empty , can still pretty access methods on class this:

@user = user.new @user.first_name = "leo" @user.save! 

and know it.

migrations files allow modify database in incremental steps while keeping sane versioning on database schema.

of course, rails complain if try call things model don't exist in database or activerecord::base parent class.

@user = user.new @user.awesome #=> undefined method `awesome` #<user:some_object_id> 

as migrations, can have multiple migrations affect 1 table. job know attributes you've added model. rails rest you.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -