Rails: has_many through with polymorphic association – will this work?

You have to do: class Person < ActiveRecord::Base has_many :events has_many :meals, :through => :events, :source => :eventable, :source_type => “Meal” has_many :workouts, :through => :events, :source => :eventable, :source_type => “Workout” end This will enable you to do this: p = Person.find(1) # get a person’s meals p.meals.each do |m| puts m end # … Read more

Ruby-on-Rails: Multiple has_many :through possible?

Edit: Rails 3.1 supports nested associations. E.g: has_many :tasks has_many :assigments, :through => :tasks has_many :users, :through => :assignments There is no need for the solution given below. Refer to this screencast for more details. Original Answer You are passing a has_many :through association as a source for another has_many :through association. I don’t think … Read more

How to set up factory in FactoryBot with has_many association

Alternatively, you can use a block and skip the association keyword. This makes it possible to build objects without saving to the database (otherwise, a has_many association will save your records to the db, even if you use the build function instead of create). FactoryGirl.define do factory :listing_with_features, :parent => :listing do |listing| features { … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)