2012-09-19 13 views
7

हाय सब मैं एक खोज के साथ दो चीजें करने की कोशिश कर रहा हूं, मॉडल विवाद चालानों के लिए है।केकफ़्पी ढूंढने की वापसी शून्य

सभी चालान जहां

invoice.receiver_id=account.id

और

dispute.invoice_id=invoice.id

वर्तमान सरणी अशक्त लौटने जब मैं डिबग पाते हैं। होनी चाहिए खोजने के बयान

में 2 परिणाम यहाँ मेरी विवादों नियंत्रक

public function index_admin(){ 


    $id = $this->Auth->User('account_id'); 

    $receiver = $this->Invoice->find('all',array(
    'conditions'=>array("AND"=>array(
    'Invoice.id'=>'Dispute.invoice_id', 
    'receiver_id'=>$id)))); 

     $this->set('id',$id); 
     $this->set('receiver', $receiver); 
    } 

यह विवादों नियंत्रक में है के रूप में मैं चालान है कि विवादों के बारे में एक सूची प्रिंट करना चाहते हैं में कोड है।

Query Error Affected Num. rows Took (ms) 
1 SELECT `Invoice`.`id`, `Invoice`.`scheduled`, `Invoice`.`paid`, `Invoice`.`sender_id`, `Invoice`.`receiver_id`, `Invoice`.`template_id`, `Invoice`.`created`, `Invoice`.`expiry_date`, `Invoice`.`total_amount`, `ReceiverAccount`.`id`, `ReceiverAccount`.`street`, `ReceiverAccount`.`city`, `ReceiverAccount`.`postcode`, `ReceiverAccount`.`state`, `ReceiverAccount`.`country`, `ReceiverAccount`.`active`, `ReceiverAccount`.`account_name`, `ReceiverAccount`.`abn`, `SenderAccount`.`id`, `SenderAccount`.`street`, `SenderAccount`.`city`, `SenderAccount`.`postcode`, `SenderAccount`.`state`, `SenderAccount`.`country`, `SenderAccount`.`active`, `SenderAccount`.`account_name`, `SenderAccount`.`abn`, `Template`.`id`, `Template`.`name`, `Template`.`description`, `Template`.`account_id`, `Template`.`active` FROM `pra`.`invoices` AS `Invoice` LEFT JOIN `pra`.`accounts` AS `ReceiverAccount` ON (`Invoice`.`receiver_id` = `ReceiverAccount`.`id`) LEFT JOIN `pra`.`accounts` AS `SenderAccount` ON (`Invoice`.`sender_id` = `SenderAccount`.`id`) LEFT JOIN `pra`.`templates` AS `Template` ON (`Invoice`.`template_id` = `Template`.`id`) WHERE `Invoice`.`id` = 'Dispute.invoice_id' AND `Invoice`.`receiver_id` = 2 

संपादित ---------------------

invoices tables has - id, sender_id, receiver_id, amount, expiry_date, created, paid 
disputes table has - id, dispute_date, comment, active 

विवादों मॉडल इस

public $belongsTo = array(
    'Invoice' => array(
      'className' => 'Invoice', 
      'foreignKey' => 'invoice_id', 
      'conditions' => '', 
      'fields' => '', 
      'order' => '' 
      ) 
     ); 

public $hasOne = array(
     'Sender' => array(
      'className' => 'Account', 
      'foreignKey' =>'sender_id', 
      'associationForeignKey' => 'accounts_id',), 
     'Receiver'=> array(
      'className' => 'Account', 
      'foreignKey' =>'receiver_id', 
      'associationForeignKey' => 'accounts_id', 
      ) 
      ); 

विवादों की तरह दिखता है एक प्रेषक और एक रिसीवर है क्योंकि एक चालान में केवल एक विवाद हो सकता है।

+0

वार $ आईडी वापसी है पता नहीं है? –

+0

हाँ, सही ढंग से प्रिंट करता है। – user1393064

+0

और क्वेरी के बाद कुछ त्रुटि लौटा? क्या आपने इसे चेक किया है? जैसे फ़ील्ड नहीं मिला, टेबल नहीं मिला? –

उत्तर

1

इस कोड का प्रयास करें: मैं अगर तालिका नाम चालान

corrct मूल्य के साथ
$id = $this->Auth->User('account_id'); 

$options['joins'] = array( 
    array(
      'table' => 'invoices', 
      'alias' => 'i', 
      'type' => 'INNER', 
      'conditions' => array(   
       'i.id' => 'invoice_id', 
        'i.receiver_id' => $id  
       )  
    )); 

$receiver = $this->Dispute->find('all', $options); 

    $this->set('id',$id); 
    $this->set('receiver', $receiver); 
+0

एक खाली सरणी के साथ आता है – user1393064

+0

अपने विचार में इस तरह की क्वेरी को प्रिंट करने का प्रयास करें यदि आपने इस विकल्प को अनुमति दी है: तत्व ('sql_dump'); ?> और क्वेरी देखें यदि कुछ फ़ील्ड खाली हैं या अच्छा नहीं है –

+0

कुछ भी नहीं आता है। – user1393064

0
public function index_admin(){ 

    $id = $this->Auth->User('account_id'); 


    $this->Invoice->bindModel(array('hasMany'=>array('Dispute' => array ('className' => 'Dispute','foreignKey' => 'invoice_id')))); 

    $receiver = $this->Invoice->find('all',array('conditions'=>array('Invoice.receiver_id'=>$id))); 

    $this->set('id',$id); 
    $this->set('receiver', $receiver); 

    } 

============ अपडेट किया गया उत्तर ================

public function index_admin(){ 

    $id = $this->Auth->User('account_id'); 


    $this->Invoice->bindModel(array('hasMany'=>array('Dispute' => array ('className' => 'Dispute','foreignKey' => 'invoice_id','conditions'=>array('receiver_id'=>$id))))); 

    $receiver = $this->Invoice->find('all'); 

    $this->set('id',$id); 
    $this->set('receiver', $receiver); 

} 

मेरी अद्यतन जवाब की कोशिश करो और जाने मुझे पता है अगर आप DisputeController में हैं

+0

लौटाती है, यह उन चालानों को प्रिंट करती है जिनमें विवाद नहीं होते हैं। – user1393064

+0

@ user1393064: कृपया विवाद तालिका में रिकॉर्ड dispute.invoice_id = invoice.id की जांच करें – chetanspeed511987

+0

ने इसे 5 रिकॉर्ड प्रिंट करने की जांच की है और केवल 3 – user1393064

संबंधित मुद्दे