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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T16:34:03+00:00 2026-05-20T16:34:03+00:00

I’m trying to figure out how to model a Device/Service relationship. I’m using Rails

  • 0

I’m trying to figure out how to model a Device/Service relationship.
I’m using Rails 3 and MongoDB/Mongoid.
The Rails app is for monitoring IP networks.

  • A device on the network (workstation, server, etc.) is represented using a Device model.
  • A service is a service such as HTTP, SMTP, SSH and each service “type” (HTTP, SMTP, SSH) can be associated with many devices.
  • Each service “type” may have some options that can be set when associated with
    a specific device (I’m thinking HTTP could have a port option if the HTTP service isn’t
    running on port 80 for example).

In the view when a user manually adds a device I need some way of allowing them to pick
the services they want the app to monitor.

Further, if the user tries to run an automatic device discovery I would like to go through the services the app supports and query the device to see if the device supports that service.

Lastly, a job runs at a certain interval to pull in new data from each device in the DB.
In that polling job I need some way of querying each service associated with the device and then saving the data (service up/down, etc.) that is specific to the device/service relationship. This is where I’m stuck. I don’t know how to do this.
Do I need a third model? How do I specify this data in my model?
Or perhaps I’m going about this all wrong and there is a better way of representing
what I want to do?

This is what my model code looks like now:

device.rb

class Device
    include Mongoid::Document

    field :name
    field :ip_address

    references_many :services

    def polll
        # psuedocode

        for each service
            query service
        end

        # save data back to DB
        update_attributes(...)
    end
end

service.rb

class Service
    include Mongoid::Document

    field :name
    field :description

    references_many :devices
end
  • 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-20T16:34:04+00:00Added an answer on May 20, 2026 at 4:34 pm

    In a relational database, what you would actually need is a has_many through call with a join model specified.

    class Device
      has_many :ports
      has_many :services, :through => :ports
    end
    

    Here you would do the same for the Service model and add a Port model as the join one. However, since you’re using Mongo, I’m gonna suggest that you embed Service into Device. This makes querying much much easier and a Service really shouldn’t be managed without a Device present. Don’t worry about data duplication, because what you’ll have is a more natural representation of your data model.

    Here’s a doc page for Mongoid’s syntax for associations, including the embedded ones, http://mongoid.org/docs/associations/

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am using Paperclip to handle profile photo uploads in my app. They upload
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

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.