Magento – the difference between `joinField` and `joinTable` in collections

collection;eavmagento-1

In the file app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php, there is a function named joinField and there is another joinTable.

If fields are actually columns in the flat tables, what does it mean to join them? An in what circumstance I should use joinTable instead? Can they both be used interchangeably?

Best Answer

Both methods are almost identical, the difference is that joinField() only selects a single column from the joined table, while you can specify an array of columns in joinTable`.

So you can always use joinTable instead of joinField. The example

 joinField('country_name', 'directory/country_name', 'name', 'country_id=shipping_country', "{{table}}.language_code='en'", 'left')

is the same as

 joinTable('directory/country_name', 'country_id=shipping_country', ['country_name' => 'name'], "{{table}}.language_code='en'", 'left')

But joinField() should not be used if you need more than one column of the joined table.