PhoenixPeopleTest - wendysmoak/wiki GitHub Wiki

= Phoenix People Test =

Trying to model a Couple which has foreign keys back to two Person records.

Discussion of modeling marriage in databases: http://qntm.org/gay

Project is https://github.com/wsmoak/people_test

mix phoenix.new people_test
cd people_test
mix ecto.create
mix phoenix.gen.html Person people name:string age:integer
mix ecto.migrate
mix phoenix.gen.html Couple couples partner1_id:references:people partner2_id:references:people
mix ecto.migrate
# Add a form for /couple/new

Adding a couple does not fill in the fields in the database. Fixed it at the database prompt.

# UPDATE couples set partner1_id = 1 where id=3;
# UPDATE couples set partner2_id = 2 where id=3;

These are Associations, so I also tried:

+    #TODO: use the params to read in the two different person records and put those in the changeset?  (Doesn't work at the console though.)
+    # person1 = PeopleTest.Repo.get!(PeopleTest.Person, 1)
+    # person2 = PeopleTest.Repo.get!(PeopleTest.Person, 2)
+    # changeset = PeopleTest.Couple.changeset( %Couple{partner1: person1, partner2: person2})
+    #  changeset is NOT VALID