为什么一样的查询,不一样的查询字符而已。结果却一个报错,一个正常,有谁遇到过类似问题吗? ruby version: 2.1.5 rails version: 3.2.18
class Contract < ActiveRecord::Base #table in DB1
belongs_to :partner_relationship,
business_unit.rb :class_name => "Relationship",
:foreign_key => :partner_business_entity_id
end
class Relationship < ActiveRecord::Base # table in DB2
end
[103] pry(main)> Contract.where("contract.name like 'ww.'").includes(:partner_relationship)
SQL (0.7ms) SELECT `contract`.`id` AS t0_r0, `contract`.`network_id` AS t0_r1, `contract`.`name` AS t0_r2, `contract`.`global_name` AS t0_r3, `contract`.`description` AS t0_r4, `contract`.`business_entity_id` AS t0_r5, `contract`.`partner_business_entity_id` AS t0_r6, `contract`.`contract_type` AS t0_r7, `contract`.`stage` AS t0_r8, `contract`.`state` AS t0_r9, `contract`.`billing_recurrence_id` AS t0_r10, `contract`.`billing_start_date` AS t0_r11, `contract`.`effective_start_date` AS t0_r12, `contract`.`effective_end_date` AS t0_r13, `contract`.`original_reference_id` AS t0_r14, `contract`.`created_at` AS t0_r15, `contract`.`updated_at` AS t0_r16, `contract`.`deleted_at` AS t0_r17, `contract`.`old_partner_business_entity_id` AS t0_r18, `contract`.`start_date` AS t0_r19, `contract`.`end_date` AS t0_r20, `relationship`.`id` AS t1_r0, `relationship`.`description` AS t1_r1, `relationship`.`network_from_id` AS t1_r2, `relationship`.`network_from_contact_id` AS t1_r3, `relationship`.`to_entity_type` AS t1_r4, `relationship`.`to_id` AS t1_r5, `relationship`.`to_contact_id` AS t1_r6, `relationship`.`relationship_type` AS t1_r7, `relationship`.`third_party_adserver_redirect_type` AS t1_r8, `relationship`.`third_party_adserver_conversion_template` AS t1_r9, `relationship`.`video_revenue_share` AS t1_r10, `relationship`.`video_revenue_flat_fee` AS t1_r11, `relationship`.`site_revenue_share` AS t1_r12, `relationship`.`site_revenue_flat_fee` AS t1_r13, `relationship`.`financial_term_notes` AS t1_r14, `relationship`.`default_bidded_ecpm` AS t1_r15, `relationship`.`active` AS t1_r16, `relationship`.`internal_id` AS t1_r17, `relationship`.`updated_at` AS t1_r18, `relationship`.`created_at` AS t1_r19, `relationship`.`distributor_cap_volume` AS t1_r20, `relationship`.`distributor_cap_period` AS t1_r21, `relationship`.`active_time` AS t1_r22, `relationship`.`role_id` AS t1_r23, `relationship`.`deleted_at` AS t1_r24 FROM `contract` LEFT OUTER JOIN `relationship` ON `relationship`.`id` = `contract`.`partner_business_entity_id` WHERE `contract`.`deleted_at` IS NULL AND (contract.name like 'ww.')
Mysql2::Error: Table 'fwrpm_oltp.relationship' doesn't exist: SELECT `contract`.`id` AS t0_r0, `contract`.`network_id` AS t0_r1, `contract`.`name` AS t0_r2, `contract`.`global_name` AS t0_r3, `contract`.`description` AS t0_r4, `contract`.`business_entity_id` AS t0_r5, `contract`.`partner_business_entity_id` AS t0_r6, `contract`.`contract_type` AS t0_r7, `contract`.`stage` AS t0_r8, `contract`.`state` AS t0_r9, `contract`.`billing_recurrence_id` AS t0_r10, `contract`.`billing_start_date` AS t0_r11, `contract`.`effective_start_date` AS t0_r12, `contract`.`effective_end_date` AS t0_r13, `contract`.`original_reference_id` AS t0_r14, `contract`.`created_at` AS t0_r15, `contract`.`updated_at` AS t0_r16, `contract`.`deleted_at` AS t0_r17, `contract`.`old_partner_business_entity_id` AS t0_r18, `contract`.`start_date` AS t0_r19, `contract`.`end_date` AS t0_r20, `relationship`.`id` AS t1_r0, `relationship`.`description` AS t1_r1, `relationship`.`network_from_id` AS t1_r2, `relationship`.`network_from_contact_id` AS t1_r3, `relationship`.`to_entity_type` AS t1_r4, `relationship`.`to_id` AS t1_r5, `relationship`.`to_contact_id` AS t1_r6, `relationship`.`relationship_type` AS t1_r7, `relationship`.`third_party_adserver_redirect_type` AS t1_r8, `relationship`.`third_party_adserver_conversion_template` AS t1_r9, `relationship`.`video_revenue_share` AS t1_r10, `relationship`.`video_revenue_flat_fee` AS t1_r11, `relationship`.`site_revenue_share` AS t1_r12, `relationship`.`site_revenue_flat_fee` AS t1_r13, `relationship`.`financial_term_notes` AS t1_r14, `relationship`.`default_bidded_ecpm` AS t1_r15, `relationship`.`active` AS t1_r16, `relationship`.`internal_id` AS t1_r17, `relationship`.`updated_at` AS t1_r18, `relationship`.`created_at` AS t1_r19, `relationship`.`distributor_cap_volume` AS t1_r20, `relationship`.`distributor_cap_period` AS t1_r21, `relationship`.`active_time` AS t1_r22, `relationship`.`role_id` AS t1_r23, `relationship`.`deleted_at` AS t1_r24 FROM `contract` LEFT OUTER JOIN `relationship` ON `relationship`.`id` = `contract`.`partner_business_entity_id` WHERE `contract`.`deleted_at` IS NULL AND (contract.name like 'ww.')
=> #<%<f66e6697Class:%<f66e6697ActiveRecord::Relation:0x007ff9e7d60888>>:0x3ffcf3eb0444>
[104] pry(main)> Contract.where("contract.name like 'w.'").includes(:partner_relationship)
Contract Load (0.4ms) SELECT `contract`.* FROM `contract` WHERE `contract`.`deleted_at` IS NULL AND (contract.name like 'w.')
=> []