ROR中,多重一对多的关系应该怎么用:through来表示啊?

比如模型是这样:
[code="ruby"]
class Province < ActiveRecord::Base

has_many :cities

end

class City < ActiveRecord::Base

has_many :factories

belongs_to :province
end

class Factory < ActiveRecod::Base

has_many :products
belongs_to :city
end

class Product < ActiveRecord::Base

belongs_to :factory
end
[/code]
是不是应该直接弄一个:through来表示Product和Province之间的关联呢?可是这样的:through怎么写啊?我试了半天都不中啊……

主要我是想查找Product表里面,Province包含某字符的记录,不用:through而用别的方法,能达到目的也行……

  1. class Province < ActiveRecord::Base
  2. has_many :cities
  3. has_many :products through :cities
  4. end

  5. class City < ActiveRecord::Base
  6. has_many :factories
  7. belongs_to :province has_many :products throught:factories
  8. end

    1. class Factory < ActiveRecod::Base
    2. has_many :products
    3. belongs_to :city
    4. end

    5. class Product < ActiveRecord::Base
    6. belongs_to :factory
    7. end

试试看。

[code="ruby"]
class Province < ActiveRecord::Base

has_many :cities

end

class City < ActiveRecord::Base

has_many :factories

belongs_to :province
end

class Factory < ActiveRecod::Base

has_many :products
belongs_to :city
end

class Product < ActiveRecord::Base

belongs_to :factory
end
[/code]