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

  • SEARCH
  • Home
  • 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 4003622
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T08:10:30+00:00 2026-05-20T08:10:30+00:00

I have a simple question, but can’t seem to find any solution, though I

  • 0

I have a simple question, but can’t seem to find any solution, though I have found things that are similar, but just not exactly what I am looking for.

I have an application where a User has many Assets through the class UserAsset. I want to be able to do current_user.user_assets , but I only want to return records that have an Asset with a specified field value of “active”.

This post is similar but I need to use the main model not the join model as a filter.

class UserAsset < ActiveRecord::Base
  belongs_to :asset
  belongs_to :user
end

class Asset < ActiveRecord::Base
  has_many :user_assets
  has_many :users, :through => :user_assets
end

class User < ActiveRecord::Base
  has_many :user_assets
  has_many :assets, :through => :user_assets
end

I tried setting the default scope on Asset, and also some conditions on the has many (user_assets) relationship, but rails is failing to consider the join on the Assets table. ie Unknown column ‘asset.live’ in ‘where clause’. Trying to achieve the following:

 @active_user_assets = current_user.user_assets  #only where assets.active = true

So how do I use conditions or scopes to achieve this? I need the user_asset object because it contains info about the relationship that is relevant.

Thanks in advance!

  • 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-05-20T08:10:31+00:00Added an answer on May 20, 2026 at 8:10 am

    You want current_user.assets, then your scopes should work.

    Oh, but you want the user_assets. Hmm. I think you need the :include clause to find() but where to put it, I can’t be arsed to think of right now.

    Perhaps

    current_user.user_assets.find(:all, :include => :assets).where('asset.live=?', true)
    

    (I’m not on Rails 3 yet, so that’s going to be mangled)

    Are you using :through when you really want a HABTM?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a simple question but I can't seem to find the solution.
I have a very simple question, but can't seem to find a strait answer
I have a simple question, but i can't find a solution for it. I
I have a simple question, I think, but I can't find the solution for
simple question maybe but can't find solution. I have button for refresh/update some contents
This is probably a really simple question but I can't seem to find anything
I have a seemingly simple question, but can't find the answer. I have a
I have a simple question that I can't find anywhere over the internet, how
This seems like a simple question but I can't seem to find an answer
Probably a long question for a simple solution, but here goes... I have a

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.