여기에 무슨 일이 일어나는지 잘 모르겠습니다. 내가 구독에 제품의 낮은 가격을 비교하기 위해 노력하고있어rails : 관련 모델의 열 사용 :
class Subscription < ActiveRecord::Base
belongs_to :subscriber, :class_name => "User"
belongs_to :subscribable, :polymorphic => true
end
create_table :products do |t|
t.string :name
t.decimal :price
t.decimal :cost_per_unit
t.integer :user_id
end
create_table :subscriptions do |t|
t.string :name
t.decimal :price
t.decimal :cost_per_unit
t.integer :subscriber_id
t.integer :subscribable_id
t.string :subscribable_type
end
class Product < ActiveRecord::Base
has_many :subscriptions, :as => :subscribable, :dependent => :destroy
def self.lower_prices
Product.includes(:subscriptions).
where("products.price < subscriptions.price OR products.cost_per_unit < subscriptions.cost_per_unit")
end
end
를하지만 나에게 오류 제공합니다 :
ActiveRecord::StatementInvalid in Pages#subscribed_products
PGError: ERROR: missing FROM-clause entry for table "subscriptions"
LINE 1: ... WHERE (user_id != 2) AND (products.price < subscripti...
^
: SELECT COUNT(*) FROM "products" WHERE (user_id != 2) AND (products.price < subscriptions.price OR products.cost_per_unit < subscriptions.cost_per_unit)
을 내 협회와 함께 작동 내가 만들려고 해요 범위를 가지고
여기에 무슨 문제가 있습니까?
'def'가 누락 되었습니까? –
@DaveNewton 예, 감사합니다. – LearningRoR
쿼리에 관련 모델 구독이 표시되지 않습니다. 올바른 모델 이름이 맞는지 확인하십시오. – naren