Skip to content

Instantly share code, notes, and snippets.

@lanetteam-bhavin
Last active Dec 19, 2015
Embed
What would you like to do?
class Employee < ActiveRecord::Base
has_many :employeeskill
has_many :skill
end
class Employeeskill < ActiveRecord::Base
belongs_to :employee
has_many :skill,:foreign_key => "skill_id"
end
irb(main):017:0> Employeeskill.joins(:skill).includes(:skill)
←[1m←[35mSQL (1.0ms)←[0m SELECT `employeeskills`.`id` AS t0_r0, `employeeskil
ls`.`employee_id` AS t0_r1, `employeeskills`.`skill_id` AS t0_r2, `employeeskill
s`.`created_at` AS t0_r3, `employeeskills`.`updated_at` AS t0_r4, `skills`.`id`
AS t1_r0, `skills`.`skill_name` AS t1_r1, `skills`.`created_at` AS t1_r2, `skill
s`.`updated_at` AS t1_r3 FROM `employeeskills` INNER JOIN `skills` ON `skills`.`
skill_id` = `employeeskills`.`id`
Mysql2::Error: Unknown column 'skills.skill_id' in 'on clause': SELECT `employee
skills`.`id` AS t0_r0, `employeeskills`.`employee_id` AS t0_r1, `employeeskills`
.`skill_id` AS t0_r2, `employeeskills`.`created_at` AS t0_r3, `employeeskills`.`
updated_at` AS t0_r4, `skills`.`id` AS t1_r0, `skills`.`skill_name` AS t1_r1, `s
kills`.`created_at` AS t1_r2, `skills`.`updated_at` AS t1_r3 FROM `employeeskill
s` INNER JOIN `skills` ON `skills`.`skill_id` = `employeeskills`.`id`
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'skills.skill_id'
in 'on clause': SELECT `employeeskills`.`id` AS t0_r0, `employeeskills`.`employe
e_id` AS t0_r1, `employeeskills`.`skill_id` AS t0_r2, `employeeskills`.`created_
at` AS t0_r3, `employeeskills`.`updated_at` AS t0_r4, `skills`.`id` AS t1_r0, `s
kills`.`skill_name` AS t1_r1, `skills`.`created_at` AS t1_r2, `skills`.`updated_
at` AS t1_r3 FROM `employeeskills` INNER JOIN `skills` ON `skills`.`skill_id` =
`employeeskills`.`id`
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:28
6:in `query'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:28
6:in `block in execute'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/connection_adapters/abstract_adapter.rb:425:in `
block in log'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activesup
port-4.0.0.rc2/lib/active_support/notifications/instrumenter.rb:20:in `instrumen
t'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/connection_adapters/abstract_adapter.rb:420:in `
log'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/connection_adapters/abstract_mysql_adapter.rb:28
6:in `execute'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/connection_adapters/mysql2_adapter.rb:220:in `ex
ecute'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/connection_adapters/mysql2_adapter.rb:224:in `ex
ec_query'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/connection_adapters/mysql2_adapter.rb:233:in `se
lect'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/connection_adapters/abstract/database_statements
.rb:24:in `select_all'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/connection_adapters/abstract/query_cache.rb:63:i
n `select_all'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/relation/finder_methods.rb:206:in `find_with_ass
ociations'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/relation.rb:585:in `exec_queries'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/relation.rb:471:in `load'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/relation.rb:220:in `to_a'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/activerec
ord-4.0.0.rc2/lib/active_record/relation.rb:573:in `inspect'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-
4.0.0.rc2/lib/rails/commands/console.rb:90:in `start'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-
4.0.0.rc2/lib/rails/commands/console.rb:9:in `start'
from D:/ruby/RailsInstaller/Ruby1.9.3/lib/ruby/gems/1.9.1/gems/railties-
4.0.0.rc2/lib/rails/commands.rb:66:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'irb(main):018:0>
irb(main):010:0> Employeeskill.first.skill
←[1m←[36mEmployeeskill Load (0.0ms)←[0m ←[1mSELECT `employeeskills`.* FROM `e
mployeeskills` ORDER BY `employeeskills`.`id` ASC LIMIT 1←[0m
←[1m←[35mSkill Load (0.0ms)←[0m SELECT `skills`.* FROM `skills` WHERE `skills
`.`skill_id` = 15
Mysql2::Error: Unknown column 'skills.skill_id' in 'where clause': SELECT `skill
s`.* FROM `skills` WHERE `skills`.`skill_id` = 15
ActiveRecord::StatementInvalid: Mysql2::Error: Unknown column 'skills.skill_id'
in 'where clause': SELECT `skills`.* FROM `skills` WHERE `skills`.`skill_id` =
15
class Skill < ActiveRecord::Base
belongs_to :employee
belongs_to :employeeskill
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment