??? DataMapper can generate your database tables from their Ruby description:
class Person < DataMapper::Base
# (property definitions)
end
# Create the table based on the above properties
database.save(Person)
DataMapper defines a top-level method, database, that returns the
current database session. As a top-level method (defined on Object), it
can be used anywhere. DataMapper plays nicely, though??”the method
will not be defined if there is already another top-level method with
the same name.
It does not have ActiveRecord??™s complex migration support, which means that
any production schema changes must be done manually. But it does have a convenient
task to recreate the entire schema, destroying any data in the process:
DataMapper::Base.auto_migrate!
DataMapper is very easy to use with Rails. It detects when it is being run under Rails
and reads the config/database.yml file for a connection specification. So, everything
should be ready to go with a gem install datamapper and one line in a Rails initializer:
require 'data_mapper'
Replacing Rails Components | 273
DataMapper uses many of the same constructs as Rails. Start out by defining a model
class that inherits from DataMapper::Base:
class Person < DataMapper::Base
# ...
end
Within the class definition, property methods define fields that should be mapped
from the class to the relational database:
class Person < DataMapper::Base
property :first_name, :string
property :last_name, :string
property :biography, :text
# Associations work pretty much like ActiveRecord.
Pages:
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415