R
R
Roman Krylov2015-03-16 23:19:07
ruby
Roman Krylov, 2015-03-16 23:19:07

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

As a result, it turned out like this:
# все города в стране
Country.get('ru').cities

# все проекты в стране
Country.get('ru').projects

# все проекты в городе
City.get('sochi').projects

# все города, в которых есть проекты
Project.all.cities

# все страны, в которых есть этот проект
Project.get('forletter').countries

# вот тут суть вопроса
# все страны, в которых есть проекты
Project.all.cities.country

To get all the countries in which there are projects, you need to do this
Project.all.cities.country
. I would like to do this, but it returns an empty array =\
Project.all.countries
Help me to realize my Wishlist

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris Penkovsky, 2015-03-17
@Able1991

Have you tried project.countries?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question