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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T04:59:14+00:00 2026-06-17T04:59:14+00:00

I have such model structure: class User < ActiveRecord::Base has_many :groups, :through => :user_groups

  • 0

I have such model structure:

class User < ActiveRecord::Base
  has_many :groups, :through => :user_groups
  has_many :orders
  has_many :user_groups
end

–

class UserGroup < ActiveRecord::Base
  belongs_to :group
  belongs_to :user
end

–

class Group < ActiveRecord::Base
  has_many :user_groups
  has_many :users, :through => :user_groups
end

In model group i have field markup.
How can i for every user via it’s user_groups get group’s markup field?

I try so:

user.user_groups.each do |u|
  summ += u.groups.markup
end

Sure it is not working… But how to fetch data from third model?

  • 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-17T04:59:15+00:00Added an answer on June 17, 2026 at 4:59 am

    user.groups.map(&:markup).sum should do it just fine

    EDIT:

    I used #flat_map because I was thinking that it was a nested array. But has_many :through would combine it into a single result list, so #map will be fine

    EDIT2:

    In discussion with @VladisAzamaris, it was pointed out that the markup column is a float, so sum is more appropriate than join

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

Sidebar

Related Questions

So I have the following model structure for a django project class RawData(models.Model): user
I have a Department model with two associations to User such that class Department
I have a such model named Foo: class Foo(models.Model): name = models.CharField() entry =
I have a function in my Comic Model as such: <?php class Comic extends
Suppose I have a simple model, such as Record: @Model public class Record {
I have a data structure that looks like this (simplified version) class A(models.Model): a
I have such database structure: Class Company has a property CompanyInfoTableName Also I have
Here is model structure: Client is User, Client can be corporate or person: class
Assuming that I have such model COLORS= ( ('R', 'Red'), ('B', 'Yellow'), ('G', 'White'),
I have a model of events that has various information such as date, location,

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.