/ Published in: Rails

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
#tablas noticias(id,titulo) boletins(id,portada_id,titulo) boletins_noticias(id,noticia_id,boletin_id) #modelos class Boletin < ActiveRecord::Base has_and_belongs_to_many :noticias belongs_to :portada, :foreign_key => :portada_id, :class_name => 'Noticia' end class Noticia < ActiveRecord::Base has_and_belongs_to_many :boletins end #pruebas en consola bole=Boletin.new(:titulo => 'Boletin numero uno') bole.save noti=Noticia.new(:titulo => 'Noticia numero uno') noti.save portada=Noticia.new(:titulo => 'Noticia de portada') portada.save bole.noticias << noti bole.portada=portada
Comments
