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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:35:59+00:00 2026-06-07T17:35:59+00:00

I currently have a metric model, that can take two operands and perform a

  • 0

I currently have a metric model, that can take two operands and perform a calculation based on its operation_type, producing a result through the custom result method. This is working as expected.

In order to make this scalable, I would like to be able to use two operands (as currently), one operand and one metric, or two metrics to perform the calculation. The reason for this is that it is then scalable – I can use the results of previous operations.

Where I am stuck is how to create this self join – I imagine that I need to go down the road of a polymorphic self reference somehow, but the documentation is not leading me to the answer. I have currently got a setup with a calculated_metric model in addition, but i’m not sure if this is the way to go.

My models look as follows:

class Metric < ActiveRecord::Base
    attr_accessible :name, :operation_type_id
end

class Operand < ActiveRecord::Base
    attr_accessible :object, :attribute
end

class Calculated_metric < ActiveRecord::Base
    attr_accessible :metric_id, :calculated_metric_id
end

Any assistance would be greatly appreciated. Thanks!

EDIT: Perhaps I can clarify this a little: I currently have a separate calculated_metric model; is this the best approach to take in order to use the results of another metric in my calculation, or could I achieve this more simply by adding a left_metric and right_metric to my existing metric table (left and right are so that if the equation is a subtraction, for example, it knows which one is being taken away)? I’m not sure if this is an ideal solution, as they will be null in a large number of cases.

  • 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-07T17:36:02+00:00Added an answer on June 7, 2026 at 5:36 pm

    I believe I may have stumbled upon a possible here – rather than having the metric reference itself, I have added a metric_id column to the operand model, which means that it can refer to an object attribute or to another metric.

    I think this solution works, albeit that there will always be at least one null column in the operand model; as such, better solutions are still welcome.

    Thanks!

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

Sidebar

Related Questions

Currently I have a text object that I need to determine its bounds. I
Currently have a drop down menu that is activated on a hover (from display:none
I currently have a XSLT 2.0 Stylesheet that I am trying to remove empty
I currently have one project that currently contains multiple packages. These packages make up
I currently have a deployed app (fortworth.herokuapp.com) that I am attempting to sort movies
I currently have a large set of ASMX web services that log the incoming
I currently have an application that sends XML over TCP sockets from windows client
I have an existing asp.net application that is currently in production for more than
Currently have WebSphere with some EJBs and defined custom user registry based on DB.
I want to modify an app that currently has a UITabBarController as its initial

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.