Hello everyone I’m creating an example phoenix app just for learning. My example app is a real estate web portal, so I’m gonna publish places (houses, apartments, etc). I have defined the following entities
Place (house, apartment) 1 → n rooms
So there is a 1 to n relationship between house and rooms and is a composition (so the rooms doesn´t exist if the house doesn’t exist).
My question is, Should be the url structure like following
/houses/house_id/rooms/room_id
If so assuming I have created both entities and liveviews
mix phx.gen.live Places House houses address:string rooms:integer image_path:string
mix phx.gen.live Places Room rooms name:string image:string
and for the last one I created a migration to improve the relationship between houses and rooms
...
create table(:rooms) do
add :name, :string
add :image, :binary
add :house_id, references(:houses, on_delete: :nothing)
timestamps(type: :utc_datetime)
end
create index(:rooms, [:house_id])
end
Are the following router.ex configuration OK? fulfilled the right URL structure ?
#Houses
live "/houses", HouseLive.Index, :index
live "/houses/new", HouseLive.Index, :new
live "/houses/:id/edit", HouseLive.Index, :edit
live "/houses/:id", HouseLive.Show, :show
live "/houses/:id/show/edit", HouseLive.Show, :edit
#Rooms
live "/houses/:house_id/rooms", RoomLive.Index, :index
live "/houses/:house_id/rooms/new", RoomLive.Index, :new
live "/houses/:house_id/rooms/:id/edit", RoomLive.Index, :edit
live "/houses/:house_id/rooms/:id", RoomLive.Show, :show
live "/houses/:house_id/rooms/:id/show/edit", RoomLive.Show, :edit
Any suggestion or comment will be welcome I just keep learning and following in love with the language and the framework. Thanks in advance