Tag: 有多个

我有一个has_many关系,我想设置自定义限制和偏移量。 以及数数

HY, 我的代码: @profile.images 而且我想在时间上只获得10张图像,并且像这样一个10偏移 @profile.images(:limit => 10, :offset => 10) 而不是这样 has_many :images, :limit => 10, :offset => 10 然后我想在某种程度上计算该配置文件的所有图像。 @profile.count_images 谢谢 (: has_many :images, :foreign_key => ‘on_id’, :conditions => ‘on_type = “profile”‘ do def paginate(page = 1, limit = 10, offset = nil) page = nil if page < 1 limit = 1 if […]

Rails 4:has_many中的counter_cache:通过与dependent :: destroy的关联

虽然已经提出了类似的问题: 带有has_many的counter_cache:通过 dependent =>在“has_many through”关联上销毁 has_many:通过counter_cache 他们都没有真正解决我的问题。 我有三个模型,有一个has_many:通过关联: class User < ActiveRecord::Base has_many :administrations has_many :calendars, through: :administrations end class Calendar < ActiveRecord::Base has_many :administrations has_many :users, through: :administrations end class Administration < ActiveRecord::Base belongs_to :user belongs_to :calendar end 联接管理模型具有以下属性: id user_id calendar_id role 我想计算每个user有多少个calendars以及每个calendar有多少users 。 我打算使用counter_cache,如下所示: class Administration < ActiveRecord::Base belongs_to :user, counter_cache: :count_of_calendars […]