Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7959345
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:33:30+00:00 2026-06-04T04:33:30+00:00

I have an expenses table. It has a column invoice_id. I would like 2

  • 0

I have an expenses table. It has a column invoice_id.

I would like 2 scopes – one for billed expenses and one for not billed.
I thought I could just test to see if invoice_id was nil.

scope :notbilled, where(:invoice_id == nil)
scope :billed, where(:invoice_id != nil)

But, that doesn’t work.

Any ideas?

Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:33:31+00:00Added an answer on June 4, 2026 at 4:33 am

    For the first one, you need to use hash syntax:

    scope :notbilled, where(:invoice_id => nil)
    

    The second requires you to use raw sql:

    scope :billed, where('invoice_id is not null')
    

    You can also jump down into arel for the second one to avoid writing raw sql, but that’s an advanced topic and would end up less readable than the raw sql.

    Using direct equality won’t work, because those expressions are evaluated immediately, and are turned into their boolean equivalents because no variables are involved, so they would be interpreted as

    scope :notbilled, where(false)
    scope :billed, where(true)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table in database with users and their expenses for traveling. I
I have 2 tables with similar layout, involving INCOME and EXPENSES. The id column
i have made a company website which has the MYSQL database of accounting,inventory,expenses, etc.
I have a table in db which stores username, month, expenses, and price. User
I currently have a table where I record all my employee daily expenses John
I have One excel file. EmployeeName Expenses Ajay 2000 Vijay 1000 Ajay 1500 Vijay
I have a table called Metrics that is a self-referencing table. Meaning it has
I have 2 mysql tables like bellow: Table income Table expense id amount date
I have tables = expenses and invlines (invoice lines). Expense belongs_to Invline Invline has_many
I have the following index action: class ExpensesController < ApplicationController def index() @expenses =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.