Answer the question
In order to leave comments, you need to log in
How to make .includes work in RoR?
There are two models
class Version < ActiveRecord::Base
has_many :servers
end
class Server < ActiveRecord::Base
belongs_to :version
end
Server.includes(:version).all
- servers.each do |s|
%p= s.version.name is s.version
Answer the question
In order to leave comments, you need to log in
Perhaps your primary key indexes in the database are broken or something like that?
The query only looks like this if you don't have any version entries that have a server_id that matches servers.id. Check pg_admin3 for integrity of the database and for the presence of these fields and corresponding tables.
What is in the console after executing these commands?
Version.all.map &:server_id
Server.all.map &:version_ids
Version.includes(:server).all.map &:server_id
Server.includes(:versions).all.map &:version_ids
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question