I have problems managing the namespace , I have the following models:
class Administradora::Owner < ApplicationRecord
has_many :owner_mails, foreign_key: :administradora_owner_id
has_many :junta_mails, through: :owner_mails
end
class Junta::Mail < ApplicationRecord
has_many :owner_mails, class_name: "OwnerMail", foreign_key: :junta_mail_id
has_many :adminstradora_owners, through: :owner_mails
end
class OwnerMail < ApplicationRecord
belongs_to :administradora_owner, foreign_key: :owner_id, primary_key: :administradora_owner_id
belongs_to :junta_mail, foreign_key: :mail_id, primary_key: :mail_id
end
By console I can do the following:
Administradora::Owner.first.owner_mails
Junta::Mail.find(4).owner_mails
It works fine, but if I try:
x = OwnerMail.create(administradora_owner_id: 4,junta_mail_id: 3, created_at: "2016/04/04", updated_at: "2016/04/04")
(0.2ms) BEGIN
(0.5ms) ROLLBACK
The id 4
and 3
exist in their respective tables and the error is:
ActiveRecord :: RecordInvalid: Validation failed: Administrator owner must exist, Board mail must exist
I do not know what may be happening.