Quesito 1.
Ho due modelli:
class Engine < ActiveRecord::Base
has_and_belongs_to_many :technologies, :join_table =>
“enginetechnologies”
end
class Technology < ActiveRecord::Base
has_and_belongs_to_many :engines, :join_table => “enginetechnologies”
end
Quando creo un nuovo engine voglio associare una o più technologies.
Engine.find(1).technologies<<Technology.find(1)<<Technology.find(2)
ok, ma al successivo:
Engine.find(2).technologies<<Technology.find(1)<<Technology.find(2)
PRIMARY KEY must be unique: INSERT INTO “enginetechnologies”
(“updated_at”, “engine_id”, “technology_id”, “id”, “created_at”) VALUES
(‘2009-02-03 18:25:49’, 2, 1, 1, ‘2009-02-03 18:25:49’)
perchè l’id della join è sempre 1??? (il db è sqlite3 e la tabella ha
l’id autoincrement)
Quesito 2.
Se volessi ottimizzare le performance ed evitare la select ogni volta
che aggiungo una technology (al di là del discorso cache), come posso
fare?
Grazie ciao.