#1493 unconfirmed
Siegfried Levin

No foreign key after auto_upgrade!

Reported by Siegfried Levin | March 1st, 2011 @ 11:24 PM

With the two models.

class Person
  include DataMapper::Resource

  # Primary Key
  property :id, Integer, :key => true

  # References
  has n, :loans, "Ticket", :child_key => [:loaner_id], :constraint => :protect
  has n, :debts, "Ticket", :child_key => [:loanee_id], :constraint => :protect
end

class Ticket
  include DataMapper::Resource

  # Primary Key
  property :id, Serial

  # General Properties
  property :loan_id, UUID, :required => true, :default => lambda { |r, p| UUIDTools::UUID.random_create }, :unique_index => :loan_index
  property :loaner_id, Integer, :required => true, :unique_index => :loan_index
  property :debt_id, UUID, :required => true, :default => lambda { |r, p| UUIDTools::UUID.random_create }, :unique_index => :debt_index
  property :loanee_id, Integer, :required => true, :unique_index => :debt_index
  property :amount, Decimal, :scale => 2, :required => true
  property :started_on, Date, :required => true
  property :expired_on, Date
  property :description, String, :length => 140, :lazy => true
  property :status, Enum[:pending, :active, :cancelled, :closed], :default => :pending, :required => true

  # References
  belongs_to :loaner, "Person"
  belongs_to :loanee, "Person"

  # Validations
  validates_with_block { loaner != loanee }
  validates_with_block(:if => :expired_on) { started_on <= expired_on }
end

auto_upgrade! create no foreign key in database. ( see attachment).

Comments and changes to this ticket

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Attachments

Referenced by

Pages