add new tables and models for join through association
This commit is contained in:
@@ -129,3 +129,21 @@ class Category < ActiveRecord::Base
|
||||
has_many :tags
|
||||
belongs_to :categoriable, polymorphic: true
|
||||
end
|
||||
|
||||
class Player < ActiveRecord::Base
|
||||
include PgSearchable
|
||||
pg_search fields: %i[players.id players.name players.value], default_fields: [:name], fields_mappings: { tag: 'ptags.value' }, joins: [:ptags]
|
||||
has_many :taggings
|
||||
has_many :ptags, through: :taggings
|
||||
end
|
||||
|
||||
class Ptag < ActiveRecord::Base
|
||||
self.table_name = :ptags
|
||||
has_many :taggings
|
||||
has_many :players, through: :taggings
|
||||
end
|
||||
|
||||
class Tagging < ActiveRecord::Base
|
||||
belongs_to :player
|
||||
belongs_to :ptag
|
||||
end
|
||||
Reference in New Issue
Block a user