我有this架构。它似乎是多对多的,但它是由EclipseLink生成的,带有这些模型
public class LancamentoContabil implements Serializable {
// objects
}
public class MovimentacaoContabil implements Serializable, CheckPeriodo {
@OneToMany(cascade={CascadeType.ALL}, orphanRemoval=true)
@OrderBy("tipo DESC")
private List<LancamentoContabil> lancamentos = newArrayList();
}
我将这些类映射到Rails项目中使用:
class LancamentoContabil < ActiveRecord::Base
self.table_name = 'lancamentocontabil'
belongs_to :conta, class_name: 'PlanoConta'
belongs_to :empresa
end
class MovimentacaoContabil < ActiveRecord::Base
self.table_name = 'movimentacaocontabil'
belongs_to :empresa
has_and_belongs_to_many :lancamentos, foreign_key: 'movimentacaocontabil_id',
class_name: 'LancamentoContabil', association_foreign_key: 'lancamentos_id',
join_table: 'movimentacaocontabil_lancamentocontabil'
end
当activerecord尝试保存MovimentacaoContabil
时,我收到此错误:
ActiveRecord::StatementInvalid Exception: PG::NotNullViolation: ERROR: null value in column "movimentacaocontabil_id" violates not-null constraint
可以找到完整的sql here
我不知道这里发生了什么......欢迎任何想法