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 7626867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T05:23:01+00:00 2026-05-31T05:23:01+00:00

First, the topic. I have three models, which are linked between each other with

  • 0

First, the topic.

I have three models, which are linked between each other with a has_many :trough association like this:

#User model 

has_many :chars_del, :class_name => CharDelegated, :dependent => :destroy
has_many :chars, :through => :chars_del

#CharDelegated model
#has a field owner:integer

belongs_to :char
belongs_to :user

#Char model
#has fields name:string

has_many :chars_del, :class_name => CharDelegated
has_many :users, :through => :chars_del

What I need to do is I need to search from a User Record to find all the Chars that the particular user ownes (:owner field is true) ordered by name. I have been stuck with this for a couple hours now, so I believe that I could have missed a very simple answer… But nothing that I have tried so far did work even a bit.

UPDATE
found something that works:

user.chars.where(:char_delegateds => {:owner => 1}).order('name')

don’t know why the :chars_del gave an error, but the full table name did the job.

Andrew, your answer works well too and is a little faster on the database, thans alot.

  • 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-31T05:23:02+00:00Added an answer on May 31, 2026 at 5:23 am

    Does

    user.chars.order('name')
    

    not work? (Given user is a single User instance.)

    Edit

    Given your new information:

    CharDelegated.where(user_id: user.id, owner: true).map(&:char)
    

    should work.

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

Sidebar

Related Questions

First off, I have read through a list of postings on this topic and
Okay I have three tables that all communicate with each other. ForumTopic t ForumMessage
Hi i have three column in database 1)topic 2)subtopic 3)imagename.first i am getting all
I have some XML like this: <topics> <topic id=50/> <topic id=51/> <topic id=52/> </topics>
Ok, yes, I've read the other Qs regarding this topic, but I have several
First of all, excuse my poor topic title. I simply have no idea how
This is my first post. I know this topic has been discussed before in
First of all, sorry for this topic title, I couldn't manage to find another
I know there are a load of other questions on this topic, I think
I realise there have been a lot of discussions on this topic, but I

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.