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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:39:23+00:00 2026-06-10T06:39:23+00:00

I have these relationships: class User include Mongoid::Document has_many :orders, :class_name => ‘Order’, :inverse_of

  • 0

I have these relationships:

class User
  include Mongoid::Document
  has_many :orders, :class_name => 'Order', :inverse_of => :user
  has_many :sold_orders, :class_name => 'Order', :inverse_of => :seller
end

class Order
 include Mongoid::Document
 belongs_to :user, :class_name => 'User', :inverse_of => :orders
 belongs_to :seller, :class_name => 'User', :inverse_of => :sold_orders
end

If I want get all orders for current seller I run in my controller something like:

def jobs
  @orders = Order.where(seller: current_user)
  p @orders
  respond_to do |format|
      format.html { render :layout => 'centered'}
    end
end

I can see in my log console:

#<Mongoid::Criteria
  selector: {:seller=>#<User _id: 500541f81d41c82f1b000037, _type: "User", created_at: 2012-07-17 10:44:08 UTC, ....more attributes>},
  options:  {},
  class:    Order,
  embedded: false>

This is wrong because I get a user, but I want get all orders for current seller.

How can I get all orders for current seller?

Thank you!

  • 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-10T06:39:25+00:00Added an answer on June 10, 2026 at 6:39 am

    This is totally fine. What you see in console is a Mongoid::Criteria object. Mongoid is very lazy to hit the database and does it only when it absolutely needs to. So instead of accessing the databse here

        @orders = Order.where(seller: current_user)
    

    it only keeps the proxy object and will load the orders when you try to do something on that data. So in order to get your orders in console you may do this:

        p @orders.to_a
    

    Moreover, Mongoid does not support .where(seller: current_user). You need to create your query based on ids for relations so you should build your query like this:

        @orders = Order.where(seller_id: current_user.id)
    

    Another thing is – you have relations defined so I would use them instead of creating the query yourself so instead of

        @orders = Order.where(seller_id: current_user.id)
    

    you can use

        @orders = current_user.solo_orders
    

    and you don’t have to worry if you need to use seller or seller_id

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

Sidebar

Related Questions

I have these tables: comments uid id pid pages pid user users id rank
I have these simplified types: public class DataBean extends ZZZZZ { public String name;
Noob question. I have this situation where I have these objects: class Address {
I have two entities, projects and users. These are modeled in Rails using Mongoid
In my project, I have a self-referential association. I have a User model: class
I have the following model classes declared by SQLAlchemy: class User(Base): id = Column(Integer,
I have User and Album models with HABTM relationship class Album < ActiveRecord::Base has_and_belongs_to_many
I have a model like public class User { [Key] public long UserId {
Background In a PostgreSQL 9.0 database, there are various tables that have many-to-many relationships.
I have these 3 tables: and I'm using this code to join them together

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.