Class: AmazonBrowseNode

Inherits:
ApplicationRecord show all
Defined in:
app/models/amazon_browse_node.rb

Overview

== Schema Information

Table name: amazon_browse_nodes
Database name: primary

id :bigint not null, primary key
item_type_keyword :string
node_path :text not null
created_at :datetime not null
updated_at :datetime not null
amazon_marketplace_id :integer not null
node_id :string not null

Indexes

index_amazon_browse_nodes_on_item_type_keyword (item_type_keyword) USING gin
index_amazon_browse_nodes_on_node_id (node_id)
index_amazon_browse_nodes_on_node_path (node_path) USING gin
unique_amazon_browse_nodes (amazon_marketplace_id, node_id, COALESCE(item_type_keyword, ''::character varying))

Instance Attribute Summary collapse

Has and belongs to many collapse

Belongs to collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#node_idObject (readonly)



26
# File 'app/models/amazon_browse_node.rb', line 26

validates :node_id, presence: true

#node_pathObject (readonly)



27
# File 'app/models/amazon_browse_node.rb', line 27

validates :node_path, presence: true

Class Method Details

.search_nodeActiveRecord::Relation<AmazonBrowseNode>

A relation of AmazonBrowseNodes that are search node. Active Record Scope

Returns:

See Also:



29
30
31
32
33
34
# File 'app/models/amazon_browse_node.rb', line 29

scope :search_node, ->(q) {
  q_wild = "'%#{q}%'".sql_safe
  where(AmazonBrowseNode[:node_id].eq(q)
               .or(AmazonBrowseNode[:node_path].matches(q_wild))
               .or(AmazonBrowseNode[:item_type_keyword].matches(q_wild)))
}

Instance Method Details

#amazon_marketplaceAmazonMarketplace



25
# File 'app/models/amazon_browse_node.rb', line 25

belongs_to :amazon_marketplace

#amazon_variationsActiveRecord::Relation<AmazonVariation>

Returns:

See Also:



23
# File 'app/models/amazon_browse_node.rb', line 23

has_and_belongs_to_many :amazon_variations

#catalog_itemsActiveRecord::Relation<CatalogItem>

Returns:

See Also:



22
# File 'app/models/amazon_browse_node.rb', line 22

has_and_belongs_to_many :catalog_items

#to_sObject



36
37
38
# File 'app/models/amazon_browse_node.rb', line 36

def to_s
  %(#{node_id} - #{node_path}#{(+' (' + item_type_keyword + ')') if item_type_keyword} [#{amazon_marketplace.country.iso}])
end