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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T17:04:12+00:00 2026-06-04T17:04:12+00:00

why is my model taking it consistently to return false everytime I try input

  • 0

why is my model taking it consistently to return false everytime I try input two names into my database. here is my entire model. All I’m doing is checking to see that both to/biller, partytwo/partyone exist in the relationship table. when i check debug kit, it shows that the form is taking in the correct variables but when I check this->validationErrors – it comes back as nothing? please help.

class Invoice extends AppModel{ 
        var $name='Invoice'; 
        public $useTable = 'invoices';
        public $primaryKey = 'id';
        public $belongsTo = array(
        'Relationship' =>array(
            'className' => 'Relationship',
            'foreignKey' =>'relationship_id',
            )
        ); 
        var $validate = array(
            'to' => array(
                'relationshipExists' => array(
                    'rule' => array(
                        'relationshipExists',
                        ),
                    'message' => 'sorry you dont have a relationship with that user.'
                    ),
                ),
            );

        public function relationshipExists($check){ 
            $relationshipExists=$this->Relationship->find('count', array('conditions' => array('Relationship.partyone','Relationship.partytwo'=>$check)));
                if ($relationshipExists == true) {
                    return TRUE;
                    }
                else
                    return FALSE;
                    }}

-relationship model

<?php

class Relationship extends AppModel
{

    var $name = 'Relationship';
    public $useTable = 'relationships_users';
    public $hasMany = array(
        'Invoice' =>
            array(
                'className'              => 'Invoice',
                'joinTable'              => 'invoice',
                'foreignKey'             => 'invoice_id'));
    public $belongsTo = array(
        'User' =>array(
            'className' => 'User',
            'foreignKey' =>'partyone','partytwo',
            'associationForeignKey'  => 'username',
            )); 

    var $validate = array(
        'date' => array(
            'rule' => array(
                'datevalidation',
                'systemDate'
            ),
            'message' => 'Current Date and System Date is mismatched'
        ),
        'partytwo' => array(
            'userExists' => array(
                'rule' => array(
                    'userExists',
                ),
                'message' => 'That username doesnt exist.'
            ),
        ),
    );

    function datevalidation($field = array(), $compare_field = null)
    {
        if ($field['date'] > $compare_field)
            return TRUE;
        else
            return FALSE;
    }

    function userExists($check)
    {   
        $userExists = $this->User->find('count', array('conditions' => array('User.username'=>$check)));
        if ($userExists == 1) {
           return TRUE;
        }
        else
            return FALSE;
    }

}
  • 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-04T17:04:13+00:00Added an answer on June 4, 2026 at 5:04 pm

    Your find is going to do interesting things…

    $relationshipExists=$this->Relationship->find('count', array(
      'conditions' => array(
        'Relationship.partyone',
        'Relationship.partytwo' => $check
      )
    ));
    

    This would probably produce something similar to

    SELECT COUNT(*) FROM relationships as Relationship 
      WHERE Relationship.partyone = 0
      AND Relationship.partytwo = Array;
    

    This is because you’re passing nothing to Relationship.partyone and an array to partytwo. You’ll need to change it to something like this:

    $relationshipExists=$this->Relationship->find('count', array(
      'conditions' => array(
        'Relationship.partyone <>' => null,
        'Relationship.partytwo' => current($check) // get the value from the passed var
      )
    ));
    

    Which would produce something like

    SELECT COUNT(*) FROM relationships as Relationship 
      WHERE Relationship.partyone IS NOT NULL
      AND Relationship.partytwo = 'fieldvalue';
    

    Debug $check to understand what value is being sent to your validation message, and debug the find results to see the results. Also, look at the SQL log to see the SQL it generated. This should give you a better understanding of what’s happening.

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

Sidebar

Related Questions

I'm taking the plunge into iPhone development after about two years working with django.
Using Model->find('all') returns an array with the following structure: array( 0 => array('Model1' =>
Here is a simple model: class TakingCourse(models.Model): course = models.ForeignKey(Course) term = models.ForeignKey(Term) Instead
I've got this model: class Visit(models.Model): timestamp = models.DateTimeField(editable=False) ip_address = models.IPAddressField(editable=False) If a
I've got a model that's migrating sucessfully but is taking 15-20 seconds. (Obviously this
Taking the following object model: public abstract class Entity { public Guid Id {
Does someone know what is solution for taking instances of commented model ordered by
I am using an ADO .Net Entity Model for querying a MySQL database. I
Background: I started to create logical database model for ASP.NET MVC web site. I
I have a B2B we app having lots of forms taking input from registered

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.