简体   繁体   中英

ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR: in rails query

Hi I have included given code

 Spree::Order.includes(:ship_address).where('ship_address.country_id = ?', 52).references(:spree_address).count

and i am facing given error

 (1.1ms)  SELECT COUNT(DISTINCT "spree_orders"."id") FROM "spree_orders" LEFT OUTER JOIN "spree_addresses" ON "spree_addresses"."id" = "spree_orders"."ship_address_id" WHERE (ship_address.country_id = 52)
PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "ship_address"
LINE 1: ...s"."id" = "spree_orders"."ship_address_id" WHERE (ship_addre...
                                                             ^
: SELECT COUNT(DISTINCT "spree_orders"."id") FROM "spree_orders" LEFT OUTER JOIN "spree_addresses" ON "spree_addresses"."id" = "spree_orders"."ship_address_id" WHERE (ship_address.country_id = 52)
ActiveRecord::StatementInvalid: PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "ship_address"
LINE 1: ...s"."id" = "spree_orders"."ship_address_id" WHERE (ship_addre...
                                                             ^
: SELECT COUNT(DISTINCT "spree_orders"."id") FROM "spree_orders" LEFT OUTER JOIN "spree_addresses" ON "spree_addresses"."id" = "spree_orders"."ship_address_id" WHERE (ship_address.country_id = 52)
from /Users/TopFormInvestment/.rvm/gems/ruby-2.1.4@skinnymint/gems/rack-mini-profiler-0.9.2/lib/patches/sql_patches.rb:160:in `exec'

Checked in spree model

belongs_to :ship_address, foreign_key: :ship_address_id, class_name: 'Spree::Address'
    alias_attribute :shipping_address, :ship_address

Please guide me how to solve this error.

查看以下查询是否有帮助。

Spree::Order.includes(:ship_address).where('spree_addresses.country_id = ?', 52).references(:spree_address).count

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM