Ulises Carreón
Joined
50 Experience
0 Lessons Completed
0 Questions Solved
Activity
We have this model called "Cliente" (cliente.rb):
class Cliente < ApplicationRecord
has_many :clientes_hardwares
has_many :clientes_notificaciones
has_many :sucursales
has_many :notificaciones, through: :clientes_notificaciones
has_many :hardwares, through: :clientes_hardwares
end
The SQL table:
And the model "Notificaciones" (notificacione.rb):
class Notificacione < ApplicationRecord
has_many :clientes_notificaciones
has_many :clientes, through: :clientes_notificaciones
end
The SQL Table:
And after that we created a join table.
class CreateJoinTableClientesNotificaciones < ActiveRecord::Migration[5.2]
def change
create_join_table :clientes, :notificaciones do |t|
t.index [:cliente_id, :notificacione_id]
t.index [:notificacione_id, :cliente_id]
end
end
end
The SQL table is called "clientes_notificaciones" and his structure very simple
The model is file(clientes_notificacione.rb):
class ClientesNotificacione < ApplicationRecord
belongs_to :cliente
belongs_to :notificacione
end
We wanna save the relation on the table but the console doesn't show the actual error.
def savenoti
@cliente = Cliente.find(6)
@cliente.clientes_notificaciones.build(
:notificacione => Notificacione.find(1)
)
@cliente.save
end
But the console shows:
wrong number of arguments (given 1, expected 0)
Am i missing something?
Regards in advance.