Reputation: 8422
in my Post model i try to eager load user (the owner of post), favorite, and comments with authors of each comment :
Post.all.includes(:user, :original => {:favorite, :comments => :author })
but it doesn't work , i get error
syntax error, unexpected ',', expecting => ...(:user, :original => [{:favorite, :comments => :author}... ...
can someone tell me where is the problem ?
Upvotes: 0
Views: 199
Reputation: 4293
As the error suggests, it's just a syntax error. You've used {:favorite, :comments => :author}
which is not a valid Hash.
Use an array as the value for :original
to do what you want:
Post.includes(:user, :original => [:favorite, :comments => :author]).all
Your confusion might stem from the omission of some curly braces for Hashes which are not required in all cases. Re-writing the above with the curly braces explicitly added might make it more clear:
Post.includes(:user, {:original => [:favorite, {:comments => :author}]}).all
Upvotes: 1