Something like this
Class Town < ActiveRecord::Base
belongs_to :player
belongs_to :island ,foreign_key :island_x
end
Update
I see there is no use of island_x
and island_y
in both the schemas
.You can just have a normal foreign_key
island_id
in the towns
table and you can make a call town.island
or island.towns
.
Update1
I got it wrong with foreignn_key
above.You can just make a method and make the matching like this
def some_method
@island_x = Island.find(params[:island_x])
@island_y = Island.find(params[:island_x])
@town_x = Town.where(:island_x => @island_x.id)
@town_y = Town.where(:island_y => @island_y.id)
end