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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:07:43+00:00 2026-06-14T07:07:43+00:00

Sinatra, Mongoid 3 There 4 models: User, Book, FavoriteBooks, ReadBooks, NewBooks . Each user

  • 0

Sinatra, Mongoid 3

There 4 models: User, Book, FavoriteBooks, ReadBooks, NewBooks. Each user has their list of the favourites, read and new books. A book belongs to a list. But it’s also possible to request an information about any book which means books should not be embedded into FavoriteBooks, ReadBooks, NewBooks.

The part of the scheme:

class Book
 include Mongoid::Document
 belongs_to :favourite_books
 belongs_to :read_books
 belongs_to :new_books 
end

class FavoriteBook
 include Mongoid::Document
 has_many :books
end

#.... the same for ReadBooks and NewBooks


class User
 include Mongoid::Document
 # what else?
end

It seems like I missed something.

What should I do to make a user “contain” the lists of FavoriteBooks, ReadBooks, NewBooks? Should I use one-to-one relationship?

  • 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-14T07:07:45+00:00Added an answer on June 14, 2026 at 7:07 am

    I think you should rethink your modeling. IMHO it should be book and user as models, and the favorite_books, read_books and new_books should all be relationhips like so:

    class User
     include Mongoid::Document
     has_many :favorite_books
     has_many :read_books
     has_many :new_books
    
     has_many :books, :through => :favorite_books
     has_many :books, :through => :read_books
     has_many :books, :through => :new_books
    end
    
    class Book
     include Mongoid::Document
     has_many :favorite_books
     has_many :read_books
     has_many :new_books
    
     has_many :users, :through => :favorite_books
     has_many :users, :through => :read_books
     has_many :users, :through => :new_books 
    end
    
    class FavoriteBook
     include Mongoid::Document
     belongs_to :books
     belongs_to :users
    end
    
    #.... the same for ReadBooks and NewBooks
    

    I think this should be a better approach. =)

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

Sidebar

Related Questions

I'm using Mongoid on Sinatra . And I use Dir.glob(File.join(File.dirname(__FILE__),'models','*.rb')).each do |file| require file
Sinatra has a before filter, but is there an easy way to implement an
I am working on Sinatra, is there a way to see the form data
I'm developing a Sinatra app which uses unicorn. Each worker is one thread, it
I run a sinatra application with mongomapper. I have models called Movie(Document) and Cover(EmbeddedDocument).
I have a Sinatra app that serves pages as read-only or editable depending on
I have a Sinatra/Mongoid application and I noticed that my mongoid model/object does not
My sinatra application has a security method which runs at the start of some
I have a problem using the paperclip with sinatra and mongoid. When I upload
Quick version (for those familiar with Mongoid & Sinatra ) : If it's not

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.