-
Notifications
You must be signed in to change notification settings - Fork 0
PDegenPortnoy/ar2dm
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
== Replacing ActiveRecord with DataMapper in a Rails application Here is a walk through of the steps I used to create this app: Pre: Install the following gems: do_mysql (or do_postgres or do_sqlite3) dm-core data_mapper fastthread json rspec 1) Generate rails framework 2) Edit config/environment.rb. Add line: config.frameworks -= [ :active_record ] 3) Load DataMapper gem. Edit config/environment.rb Add lines: config.gem "do_mysql" config.gem "dm-core" 3.1) Make sure your gems are up to date by running "sudo rake gems:install" 4) Configure database.yml 5) Create configuration file for datamapper config/initializers/datamapper.rb 6) Generate model script/generate dm_model book amount:float date:date name:string description:text --skip-migration Two ways to migrate models: A) migration 1, :create_articles do 2 up do 3 create_table :articles do 4 column :id, Integer, :serial => true, :nullable? => false 5 column :title, String 6 column :body, "TEXT" 7 end 8 end 9 10 down do 11 drop_table :articles 12 end 13 end B) Properties in your class file & DataMapper.auto_migrate! NOTE: I used A) and ran a datamapper migration. 7) Create migration for initial table: 7.1) Add config.gem "dm-migrations" to config/environment.rb 7.2) Create a migration file (no script/migrate exists!) == Only one line needed! 7.3) Create a new rake task in namespace "dm" to accomodate migrations 8) script/generate controller books index show new create delete 9) Create database mysqladmin -u root -p create dm2_dev --socket /var/run/mysqld/mysqld.sock 10) Run migration rake dm:migrate 11) Add content to files
About
ActiveRecord to DataMapper Example
Resources
Stars
Watchers
Forks
Releases
No releases published
Packages 0
No packages published