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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:00:42+00:00 2026-05-29T06:00:42+00:00

How do i validate a column in one table against entries in other tables?

  • 0

How do i validate a column in one table against entries in other tables?

The code I used to validate that the entry for column “:product_id” of table “Preperiod” exists in the column “id” of table “Product” is

validate :product_id_exists
def product_id_exists
 if Product.find_by_id(:product_id)==nil
   errors.add(:base, "Product must be defined")
 end
end

But now I get the error even when the product_id is right. What did I do wrong?

I use ruby 1.9.2 and rails 3.0.9

  • 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-29T06:00:43+00:00Added an answer on May 29, 2026 at 6:00 am
    Product.find_by_id('here you should specify value of id field ... ') == nil 
    

    so you your code should look like:

    Product.find_by_id(product_id) == nil
    

    or:

    Product.find_by_id(self.product_id) == nil
    

    or:

    Product.find_by_id(self[:product_id]) == nil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Bit confused with this one. Basically, I have a column in a table, and
I have a simple MySQL table with one column: name . I would like
I have one question that if we are creating any table in database i.e.
When im trying to validate my page on http://validator.w3.org/ i get one error that
When trying to validate my site, I get the following error: Line 188, column
Calling Validate() on an XmlDocument requires passing in a ValidationEventHandler delegate. That event function
Is it possible to validate an xml file against its associated schema using Visual
I need to validate an XML string (and not a file) against a DTD
How can I validate that my ASPNET AJAX installation is correct. I have Visual
I'm adding some columns to one of my database tables, and then populating those

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.