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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:29:30+00:00 2026-05-11T03:29:30+00:00

Given the following tables in ActiveRecord: authors sites articles I don’t know how to

  • 0

Given the following tables in ActiveRecord:

  • authors
  • sites
  • articles

I don’t know how to express that an author is paid a different amount depending on the publication, but that authors working for the same publication have different rates:

  • John publishes an article in Foo for $300
  • John publishes an article in Bar for $350
  • John publishes an article in Baz for $400
  • Dick publishes an article in Foo for $250
  • Dick publishes an article in Bar for $400

etc.

What kind of relationship am I trying to describe?

At the moment I’ve got a ‘rates’ table with author_id, site_id and amount columns. Given publication.id and author.id, I derive the cost of the article with

cost = Rate.find(:first, :conditions => ['author_id = ? and site_id = ?', author.id, site.id]).rate 

That works, but I’m not sure it’s the best way, and I’m not sure how to make sure I don’t end up with ‘John’ having two rates for ‘Baz.’

I don’t think I want code so much as I want someone to say ‘Oh, that’s a … relationship’ so I can get a grip on what I’m Googleing for.

  • 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. 2026-05-11T03:29:31+00:00Added an answer on May 11, 2026 at 3:29 am

    Its a has and belongs to many with a rich join table.

    class Author   has_many :publications, :through => :rates end  class Publication   has_many :authors, :through => :rates end  class Rate #rich join table   belongs_to :author   belongs_to :publication end 

    And you can then simplify your finding like this:

    @author.rates.find_by_site_id(123) 

    Plus you get direct access accross the join table

    @author.publications @publication.authors 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following tables orders +----+---------+---------+ | id | user_id | details | +----+---------+---------+
Given the following tables: Topic id, last_updated_child_id Response id, topic_id, updated_at How do I
Given the following tables: shows: title | basic_ticket_price ----------------+-------------------- Inception | $3.50 Romeo &
Given the following Tables: Names Id int Name varchar Properties Id int NameId varchar
Problem Given the following two tables, I'd like to select all Ids for Posts
I have the following tables: class FinalExam < ActiveRecord::Base belongs_to :course has_many :pages, :as
I've a complex ActiveRecord query that I'm building up with different scopes, depending on
Given the following tables: CREATE TABLE Employees ( first_name VARCHAR(50) NOT NULL, last_name VARCHAR(50)
I have the following models with associations as given below:- class Comment < ActiveRecord::Base
Given the following table Month Product Sales --------- ------- ----- January 1 10 January

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.