0

I have two table which are as below. I would like to match title based on first table and select title form another table for all the first table.

My code for get this resul is

$collection = Mage::getModel('specificationvalues/specificationvalues')->getCollection();
  $collection->getSelect()->join(array('ot' =>'specificationoptions'),"main_table.options = ot.specificationoptions_id",array('optiontitle' =>'ot.title'))

But it gives only 4 records

Table Structure.

    Main Table

specificationvalue

specificatinovalue_id   title       options
1                       value1        1
2                       value2        2  
3                       value3        2  
4                       value4        3  
5                       value5        3  
6                       value6        4  
7                       value7        4  
8                       value8        4  
9                       value9        4 
10                      value10       4  

Join Table

specificatinooptions

specificationoptions_id   title
1           option1
2           option2
3           option3
4           option4


Result should be

specificatinovalue_id   title       optiontitle
1                       value1        option1
2                       value2        option2  
3                       value3        option2  
4                       value4        option3  
5                       value5        option3  
6                       value6        option4  
7                       value7        option4 
8                       value8        option4  
9                       value9        option4 
10                      value10       option4
3
  • 2
    try leftjoin instead of join Commented Mar 3, 2017 at 6:39
  • No luck using joinLeft
    – MageLerner
    Commented Mar 3, 2017 at 6:42
  • Try with echoing your query by echo $collection->getSelect() and check. Or paste your query here in your question. Commented Mar 3, 2017 at 6:48

2 Answers 2

1

Try below code:

$collection =   Mage::getModel('specificationvalues/specificationvalues')->getCollection();
$collection->getSelect()->joinLeft(array('ot' =>'specificationoptions'),"main_table.options = ot.specificationoptions_id",array('optiontitle' =>'ot.title'))
0
0

Try,

$collection = Mage::getModel('specificationvalues/specificationvalues')->getCollection()->joinField('optiontitle', 
   'specificationoptions', 
   'title', 
   'specificationoptions_id=options', 
   array('title'=>array('neq' => '')),
   'left'
);
1
  • ` Call to undefined method Test_Specificationvalues_Model_Mysql4_Specificationvalues_Collection::joinField()` Errorr :(
    – MageLerner
    Commented Mar 3, 2017 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.