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

The Archive Base Latest Questions

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

In my application, I have a Widget model, a Feature model with a has_many

  • 0

In my application, I have a Widget model, a Feature model with a has_many through association by WidgetFeature table.

As per the requirements, when I am sending a WidgetFeature object, I should append the feature_name to it as well, for the given feature associated.
There are two ways of going at it:

  1. While sending the object, do this:
widget_feature_object[:feature_name] = feature_name_value

and then I can access it in my controller or view, by widget_feature_object[:feature_name] because an object has (key, value) pairs, so I can add another too.

2 . Make feature_name a Virtual Attribute in WidgetFeature model, and then create getter and setter methods for it.

From what I know, that you should use virtual attributes when you want to create a different view different from the fields actually present in the model (e.g Full name = First name + Last name).
Does the same thing fits in here too?

Also, does Rails do some caching on objects, that might get in useful when you use virtual attributes and not when I use the first approach?

What are the pros and cons of each approach and which one suits the best as per my requirements?
Thanks a lot.

  • 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-23T16:00:21+00:00Added an answer on May 23, 2026 at 4:00 pm

    I would propose an alternative approach: use delegate (documentation).

    In the WidgetFeature I would write:

    class WidgetFeature
    
      belongs_to :feature
    
      delegate :name, :to => :feature, :prefix => true
    end
    

    then you will be able to write

    f = WidgetFeature.first
    
    f.feature_name #will return f.feature.name
    

    Hope this helps.

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

Sidebar

Related Questions

I'm writing an application on qooxdoo. I have a class, which should return table
In a C# desktop application, I have a customer widget which contains a text
In a django application I have the following model: class Appointment(models.Model): #some other fields
How to copy or duplicate gtk widgets? In my application I have one huge
I have a portal application that loads external content (widgets) via an iframe. Users
I see an application have used Log.info = some info where are these logs
In my console application have an abstract Factory class Listener which contains code for
I have one question; In my ASP.NET MVC web application have to do certain
I have an game application I have written for Windows Mobile and I want
I have application which needs to use a dll (also written by me) which

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.