Answer the question
In order to leave comments, you need to log in
Projects in the City, Cities in the Country. How to find all countries in which there are projects?
Help make connections.
Described the model as follows:
class Project
include DataMapper::Resource
property :id, String, :key => true
has n, :cities, :through => Resource
# вот тут что-то не то
has n, :countries, 'Country', :through => :cities, :via => :country
end
class City
include DataMapper::Resource
property :id, String, :key => true
belongs_to :country
has n, :projects, :through => Resource
end
class Country
include DataMapper::Resource
property :id, String, :key => true
has n, :cities
has n, :projects, 'Project', :through => :cities, :via => :projects
end
# все города в стране
Country.get('ru').cities
# все проекты в стране
Country.get('ru').projects
# все проекты в городе
City.get('sochi').projects
# все города, в которых есть проекты
Project.all.cities
# все страны, в которых есть этот проект
Project.get('forletter').countries
# вот тут суть вопроса
# все страны, в которых есть проекты
Project.all.cities.country
Project.all.cities.country
Project.all.countries
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question