0

I am facing this SQLite exception error when running my application:

SQLite3::SQLException at /admin

no such column: subscription_plan.name

This is the controller code, I am facing error:

def dashboard @number = { :month => Subscription.includes(:subscription_plan).where(['subscriptions.created_at > ? AND subscriptions.amount > ? AND subscription_plan.name = ?', Time.zone.now.beginning_of_month, 0, 'month']).count, :year => Subscription.includes(:subscription_plan).where(['subscriptions.created_at > ? AND subscriptions.amount > ? AND subscription_plan.name = ?', Time.zone.now.beginning_of_month, 0, 'year']).count } end 

This is Subscription model with relation:

class Subscription < ActiveRecord::Base belongs_to :subscription_plan end 

There is no subscription_plan model in my application, but the data to this table is populated through seeds.rb file. As shown in the controller, 'month', 'year' are some of the names in subscription_plan table.

It is working fine with Rails 3.2, i don't know why it's not working with 4.2.6. Please help.

3
  • table name might be subscription_plans, try subscription_plans.name = ? Commented Jul 20, 2016 at 9:05
  • Yes, table name is subscription_plans, even it is not working. I don't know how, in the previous version they did the same, it worked. Commented Jul 20, 2016 at 9:16
  • try adding references(:subscription_plans) at the end, which was mention in my answer below. Commented Jul 20, 2016 at 9:54

3 Answers 3

2

You need to provide the table name in condition rather than association name please try

Subscription.includes(:subscription_plan).where(['subscriptions.created_at > ? AND subscriptions.amount > ? AND subscription_plans.name = ?', Time.zone.now.beginning_of_month, 0, 'month']) 
Sign up to request clarification or add additional context in comments.

Comments

1

Can you please try this.

Subscription.includes(:subscription_plan).where(["subscriptions.created_at > ? AND subscriptions.amount > ? AND subscription_plans.name = ?", Time.zone.now.beginning_of_month, 0, 'month']).references(:subscription_plans) 

Comments

0

You don't need to reference subscription in the where clause, note the plural subscription_plans.name, and the comment from power is right on about adding the references(:subscription_plans)

Subscription.includes(:subscription_plan).where(['created_at > ? AND amount > ? AND subscription_plans.name = ?, Time.zone.now.beginning_of_month, 0, 'month']).references(:subscription_plans).count 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.