Search
 
SCRIPT & CODE EXAMPLE
 

RUBY

eager load polymorphic rails

You need to add a custom belongs_to to your polymorphic model

class Shipment
  has_many :payments, as: :paymentable
end

class Payment  
  belongs_to :paymentable, polymorphic: true
  # Add a custom belongs_to that points to Shipment
  belongs_to :shipment, foreign_type: 'Shipment', foreign_key: 'paymentable_id'
end
Comment

PREVIOUS NEXT
Code Example
Ruby :: rails generate migration array default value 
Ruby :: authrenticate to artifactory grails 2.1.1 
Ruby :: ruby hash transform values 
Ruby :: integer to string ruby 
Ruby :: ruby is int 
Ruby :: ruby gem dir 
Ruby :: rspec add support folder to gem 
Ruby :: ruby read file 
Ruby :: ruby multiline comment 
Ruby :: remove first element from an array ruby 
Ruby :: rails strftime 
Ruby :: full error messages rails 
Ruby :: sort hash ruby 
Ruby :: array string ruby 
Ruby :: sort array of hashes ruby 
Ruby :: ruby read stdin 
Ruby :: rails faker url 
Ruby :: ruby array remove by index 
Ruby :: remove ascii characters from string ruby 
Ruby :: rails devise valid_password 
Ruby :: remove order by from query in rails 
Ruby :: ruby on rails scaffold generator example with belongs to relationship 
Ruby :: ruby and or 
Ruby :: ruby get min value from array 
Ruby :: ruby on rails 4.2 how to add GET route 
Ruby :: Rudy control S 
Ruby :: ruby on rails multiple models pagination 
Ruby :: rails generate controller without view ,test 
Ruby :: change elements in ruby hashes 
Ruby :: how to run one line pry 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =