
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
-
Piotr Solnica (solnic) March 5th, 2011 @ 09:57 AM
- State changed from new to unconfirmed
Which foreign key?
-
-
Dan Kubb (dkubb) March 23rd, 2011 @ 11:11 PM
@Siegfried: Did you use DataMapper.finalize after declaring the models, but before running DataMapper.auto_upgrade! ? It is responsible for inferring the foreign keys and setting them up so that the migration will add them.
-
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.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
People watching this ticket
Attachments
Referenced by
-
1503 auto_upgrade! on empty Mysql database does not create foreign key constraints Probably #1493 is related to this.