Hi,
I have a Match model with a has_many relationship to SetScores. BTW, I
wanted to use the name Sets but thought calling a table and object Set
would get me in lots of trouble ;-)
Anyway, one (tennis)match has many set_scores, now how would I best
generate the form for inserting a match?
I guess the HTML output would have to look something like:
<!-- set 1 -->
<input type="text" name="match[set_score[][set_nr]]"
/>
<input type="text" name="match[set_score[][score_opp1]]"
/>
<input type="text" name="match[set_score[][score_opp2]]"
/>
<!-- set 2 -->
<input type="text" name="match[set_score[][set_nr]]"
/>
<input type="text" name="match[set_score[][score_opp1]]"
/>
<input type="text" name="match[set_score[][score_opp2]]"
/>
or perhaps:
<!-- set 1 -->
<input type="text" name="match[set_score[1][score_opp1]]"
/>
<input type="text" name="match[set_score[1][score_opp2]]"
/>
<!-- set 2 -->
<input type="text" name="match[set_score[2][score_opp1]]"
/>
<input type="text" name="match[set_score[2][score_opp2]]"
/>
but than it wouldn''t map as neatly to the SetScore model, see below:
class SetScore < ActiveRecord::Base
end
SQL:
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;
Any help would be much appreciated!
Jeroen