2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2008-03-21 14:09:03 -04:00
|
|
|
class Club < ActiveRecord::Base
|
2019-04-05 00:44:30 -04:00
|
|
|
has_one :membership, touch: true
|
2016-08-06 13:37:57 -04:00
|
|
|
has_many :memberships, inverse_of: false
|
|
|
|
has_many :members, through: :memberships
|
2008-03-21 22:20:37 -04:00
|
|
|
has_one :sponsor
|
2016-08-06 13:37:57 -04:00
|
|
|
has_one :sponsored_member, through: :sponsor, source: :sponsorable, source_type: "Member"
|
2010-10-14 08:44:32 -04:00
|
|
|
belongs_to :category
|
2008-10-13 13:01:37 -04:00
|
|
|
|
2014-04-10 16:43:59 -04:00
|
|
|
has_many :favourites, -> { where(memberships: { favourite: true }) }, through: :memberships, source: :member
|
2013-11-10 00:28:54 -05:00
|
|
|
|
2018-11-27 13:34:20 -05:00
|
|
|
scope :general, -> { left_joins(:category).where(categories: { name: "General" }).unscope(:limit) }
|
2017-05-17 21:42:26 -04:00
|
|
|
|
2019-04-05 00:44:30 -04:00
|
|
|
accepts_nested_attributes_for :membership
|
|
|
|
|
2008-10-13 13:01:37 -04:00
|
|
|
private
|
2016-08-06 13:55:02 -04:00
|
|
|
def private_method
|
|
|
|
"I'm sorry sir, this is a *private* club, not a *pirate* club"
|
|
|
|
end
|
2010-10-14 08:44:32 -04:00
|
|
|
end
|
2014-06-17 13:11:22 -04:00
|
|
|
|
|
|
|
class SuperClub < ActiveRecord::Base
|
|
|
|
self.table_name = "clubs"
|
2014-06-19 14:04:39 -04:00
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
has_many :memberships, class_name: "SuperMembership", foreign_key: "club_id"
|
2014-06-19 14:04:39 -04:00
|
|
|
has_many :members, through: :memberships
|
|
|
|
end
|