Hello,
I tried the following and got that error and can't figure out how to
fix it... I know I can do a long way to add Turmas To a Disciplina but
using like the following would be very convinient:
p = Periodo.find(:first)
d = p.disciplinas.find(13)
d.turmas.create!(:codigo => '23A', :horario => '2a e 4a -
15-17h', :descricao => 'Turma Regular')
ActiveRecord::HasManyThroughCantAssociateThroughHasManyReflection:
Cannot modify association 'Disciplina#turmas' because the source
reflection class 'Turma' is associated to 'DisciplinaPeriodo'
via :has_many.
My models are:
class Periodo < ActiveRecord::Base
has_many :disciplina_periodos, :dependent => :destroy
has_many :disciplinas, :through => :disciplina_periodos
validates_presence_of :periodo
validates_uniqueness_of :periodo
end
class Disciplina < ActiveRecord::Base
has_one :disciplina_periodo
has_one :periodo, :through => :disciplina_periodo
has_many :disciplina_periodos, :dependent => :destroy
has_many :turmas, :through => :disciplina_periodos
validates_presence_of :codigo, :nome
validates_uniqueness_of :codigo
validates_uniqueness_of :nome
end
class DisciplinaPeriodo < ActiveRecord::Base
has_many :turmas, :dependent => :destroy
belongs_to :periodo
belongs_to :disciplina
validates_presence_of :periodo_id, :disciplina_id
validates_uniqueness_of :disciplina_id, :scope => :periodo_id
validates_uniqueness_of :periodo_id, :scope => :disciplina_id
end
class Turma < ActiveRecord::Base
belongs_to :disciplina_periodo
belongs_to :disciplina
validates_uniqueness_of :codigo, :scope => :disciplina_periodo_id
end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---