Class Lafcadio::DomainObjectField
In: lafcadio/objectField.rb
lafcadio/test.rb
Parent: ObjectField

A DomainObjectField is used to link from one domain class to another. To add such an association in a class definition, call DomainObject.domain_object:

  class Invoice < Lafcadio::DomainObject
    domain_object Client
  end

By default, the field name is assumed to be the same as the class name, only lower-cased and camel-case.

  class LineItem < Lafcadio::DomainObject
    domain_object Product         # field name 'product'
    domain_object CatalogOrder    # field name 'catalog_order'
  end

The field name can be explicitly set as the 2nd argument of DomainObject.domain_object.

  class Message < Lafcadio::DomainObject
    domain_object User, 'sender'
    domain_object User, 'recipient'
  end

Setting delete_cascade to true means that if the domain object being associated to is deleted, this domain object will also be deleted.

  class Invoice < Lafcadio::DomainObject
    domain_object Client, 'client', { 'delete_cascade' => true }
  end
  cli = Client.new( 'name' => 'big company' ).commit
  inv = Invoice.new( 'client' => cli ).commit
  cli.delete!
  inv_prime = Invoice[inv.pk_id] # => will raise DomainObjectNotFoundError

Attributes

delete_cascade  [RW] 
linked_type  [R] 

[Validate]