add new tables and models for join through association

This commit is contained in:
Bilal
2020-04-29 07:22:03 +02:00
parent fe96f682db
commit e0fae50584
3 changed files with 101 additions and 6 deletions

View File

@@ -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