
Go-Through association miss the primary key
Reported by Siegfried Levin | February 13th, 2011 @ 09:37 AM
When I use go-through association like this, there will be a
error.
class Person
include DataMapper::Resource
property :id, String, :key => true, :length => 20
property :created_at, Time
has n, :loans, :child_key => [:loaner_id], :constraint => :protect
has n, :debts, "Loan", :child_key => [:loanee_id], :constraint => :protect
has n, :loan_creations, :child_key => [:loaner_id], :constraint => :protect
has n, :debt_creations, "LoanCreation", :child_key => [:loanee_id], :constraint => :protect
has n, :loan_deletions, :through => :loans
def potential_loans
loan_creations.undone
end
def potential_debts
debt_creations.undone
end
end
class LoanDeletion
include DataMapper::Resource
belongs_to :loan, :key => true
def self.undone
all(:loan => {:status => :open})
end
def self.done
all(:loan => {:status => :closed})
end
end
Error message:
in `finalize_model': LoanDeletion must have a key to be valid (DataMapper::IncompleteModelError)
But if I give LoanDeletion model a id in Serial, the error will
be gone.
class LoanDeletion
include DataMapper::Resource
belongs_to :loan, :key => true
property :id, Serial
def self.undone
all(:loan => {:status => :open})
end
def self.done
all(:loan => {:status => :closed})
end
end
No comments found
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 »