tôi bị ném vào một dự án grails hiện và là một trong những vấn đề tôi đang gặp là khi tiết kiệm một cái gì đó đợt một, tôi nhận được lỗi: Cannot set readonly property: programId
Grails "không thể đặt thuộc tính readonly: programId"
Dưới đây là tôi tiết kiệm đoạn gây ra lỗi
// Create a batch
def batch = new Batch()
batch.name = session.batch_name
batch.startDate = new Date()
batch.endDate = new Date()
batch.programId = 120
if(batch.save()) {
...
}
Dưới đây là hàng loạt lớp tên miền của tôi
class Batch extends AbstractDomainObject{
String name
Date startDate
Date endDate
String comments
StatusType currentStatus
static belongsTo = [program:Program]
static constraints = {
name(blank:false,maxSize:100)
startDate()
endDate()
comments (nullable:true, maxSize:DEFAULT_SIZE_OF_COMMENTS)
currentStatus(nullable:true)
}
static transients= ["currentStatus"]
static mapping = {
id column:'batch_id', generator:'sequence', params:[sequence:'sq_batch']
currentStatus column:'status_type_id'
program column:'program_id'
statuses sort:'statusDate'
startDate type:'date'
endDate type:'date'
}
public String toString(){
return name
}
public Date createdDate(){
Date date=null
if(this?.statuses?.size()>0){
this?.statuses.each{
if(it.status.value==SystemConstants.STATUS_PENDING){
date = it.statusDate
}
}
}
return date
}
}
Tại sao nó không cho phép tôi thiết lập các programId
?
'ProgramId' ở đâu trong đối tượng miền của bạn? Tôi có thể thấy 'name',' startDate', 'endDate',' comments' và 'currentStatus', nhưng không có' programId' –
Tôi đã không chắc chắn nếu tôi cần thiết để thiết lập nó vì có một thuộc tính = [program: Program ]. – Catfish
Điều đó sẽ không cung cấp cho bạn một 'programId'. Bạn sẽ có một 'program.id', nhưng bạn thực sự không muốn thiết lập như thế này –