Jeroen Houben
2005-Oct-27 10:36 UTC
must a has_many association have a primary key sequence?
Hi,
I have a table "match" that has many "set_scores".
CREATE TABLE "public"."set_scores" (
"match_id" INTEGER NOT NULL,
"set_nr" SMALLINT NOT NULL,
"score_opp1" SMALLINT NOT NULL,
"score_opp2" SMALLINT NOT NULL,
CONSTRAINT "set_scores_fk" FOREIGN KEY ("match_id")
REFERENCES "public"."matches"("id")
ON DELETE CASCADE
ON UPDATE CASCADE
DEFERRABLE
INITIALLY DEFERRED
) WITH OIDS;
CREATE INDEX "match_sets_idx" ON
"public"."set_scores"
USING btree ("match_id", "set_nr");
When I create a new new match, Rails errors:
ERROR: relation "set_scores_id_seq" does not exist
/app/controllers/match_controller.rb:37:in `create''
script/server:51
It''s using a shared primary key as you can see above. Do I have to
create an additional id sequence for this to work?
Jeroen
Jeremy Kemper
2005-Oct-27 17:15 UTC
Re: must a has_many association have a primary key sequence?
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Oct 27, 2005, at 3:36 AM, Jeroen Houben wrote:> It''s using a shared primary key as you can see above. Do I have to > create an additional id sequence for this to work?Yes, each table needs its own auto-incrementing primary key. Just add ''id serial primary key''. Best, jeremy -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (Darwin) iD8DBQFDYQtHAQHALep9HFYRAvCxAJ97YOMTQklK9Ck2KW7bhu0vYj7bDgCdERNs yGywFp0LGXKI6B/0m1U4ucE=vwC6 -----END PGP SIGNATURE-----