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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:40:37+00:00 2026-06-01T22:40:37+00:00

I have two models: Client and Contract. Client has 3 attributes: id, email and

  • 0

I have two models: Client and Contract.
Client has 3 attributes: id, email and client_number.
Contract has 3 too: id, ip and client_id.
Client has_many :contracts.
Contract belongs_to :client.

With RoR I get Auto-generated methods like:

Client.find_by_email_and_client_number ‘some_email’, 1234

but I want a Auto-generated method like:

Client.find_by_email_and_client_number_and_ip ‘some_email’, 1234, ‘192.168.200.54’

using not Client’s attributes only. I want to use the ip attribute from Contract model too.

  • 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-01T22:40:39+00:00Added an answer on June 1, 2026 at 10:40 pm

    You won’t be able to achieve this with Rails’ in-built magic finder methods. But you can do it with a more direct query, like this:

    Client.includes(:contracts).where(:email => 'some_email', :ip => '192.168.200.54').where('contracts.client_number = 1234')
    

    This is an example of two of Rails’ finding mechanisms: the first is finding directly by a hash, the second is a SQL snippet.

    It does seem like what you’re actually looking for here is a relation of some sort, though. If client_number is set up as the key for the has_many association, it might be easier to query this like so:

    client = Client.find_by_client_number(1234)
    client.contracts.where(:email => 'some_email', :ip => '192.168.200.54')
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two models, Reports(belongs to client) and Clients(has many reports). A Client has
I have two models Clients and Reports. A Client has_many Reports and a Report
I have two models class Subscription < ActiveRecord::Base belongs_to :client end class Client <
I have two models: class User end class Message belongs_to :sender, :class_name=> 'User' belongs_to
I have two models, Client and PaymentOptions . class Client(models.Model): name = models.CharField(max_length=50, null=True,
I have two models, Client and PaymentOptions . class Client(models.Model): name = models.CharField(max_length=50, null=True,
I have two tables: Client(id,name,...) Purchase(id,item,date,client_id,...) They have their respective Model, with their validations.
In my Rails app, I have two models, Estimate and Client , which both
I have three models: class Client < ActiveRecord::Base has_many :balancesheets has_many :investment_assets, :through =>
I have two models in my Django application, for the purposes of storing search

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.