..
# belongs_to :company, :foreign_key => 'firm_id'
# has_many :transactions, :class => FinancialTransaction
end
DataMapper comes with a set of convenience methods that behave like ActiveRecord
object lifecycle methods. For example, the syntax to create a Person is the same as
under ActiveRecord:
>> p = Person.new :first_name => 'John', :last_name => 'Smith',
:biography => 'Something about John'
=> #
@last_name="Smith", @biography="Something about John", @id=nil>
>> p.save
=> 1
>> p
=> #@last_name="Smith", @biography="Something about John", @id=1>
Notice that under DataMapper, the attributes of Person are directly
stored as instance variables of the Person object. In ActiveRecord,
these attributes would be stored in a hash as the @attributes variable.
In some ways, DataMapper??™s approach is cleaner, as it avoids another
layer of indirection.
There are many more features behind DataMapper, and the full set of documentation
can be found at http://www.datamapper.org/. API documentation is also available
at http://datamapper.rubyforge.org/.
Ambition
Chris Wanstrath??™s Ambition project (http://errtheblog.com/post/10722) is an amazing
little experiment that turns Ruby code into SQL almost transparently. Using
Ryan Davis??™s ParseTree library, Ambition walks the Ruby abstract syntax tree and
turns various methods into their corresponding SQL queries.
Pages:
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416