1

I have created a setup script that creates new category attributes.

It works quite well, however after the setup did run, the flat tables are missing the columns and when the Magento API creates the select SQL queries, the Mysql server gives error because the column is not found:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'main_table.attribute_column_identifier' in 'field list', query was: SELECT `main_table`.`entity_id`, ...

Now I wonder what the common way is to establish it within the flat tables as well in the setup. I don't want to rebuild manually on the server.

asked Aug 28, 2015 at 14:09
2
  • Is that a typo? "attribute_column_udentifier"? Commented Aug 28, 2015 at 14:11
  • @Raj: Yes, a typo in the exemplary name. Thanks for pointing out. Commented Aug 30, 2015 at 7:51

1 Answer 1

3

Each of your custom attributes needs a source model with the following methods defined:

  1. getFlatColums(): creates the value column on the flat tables
  2. getFlatUpdateSelect(): populates the values

You can also specify an index for this column by defining getFlatIndexes().

For reference see Mage_Eav_Model_Entity_Attribute_Source_Boolean:

/**
 * Retrieve flat column definition
 *
 * @return array
 */
public function getFlatColums()
{
 $attributeCode = $this->getAttribute()->getAttributeCode();
 $column = array(
 'unsigned' => false,
 'default' => null,
 'extra' => null
 );
 if (Mage::helper('core')->useDbCompatibleMode()) {
 $column['type'] = 'tinyint(1)';
 $column['is_null'] = true;
 } else {
 $column['type'] = Varien_Db_Ddl_Table::TYPE_SMALLINT;
 $column['length'] = 1;
 $column['nullable'] = true;
 $column['comment'] = $attributeCode . ' column';
 }
 return array($attributeCode => $column);
}
/**
 * Retrieve Indexes(s) for Flat
 *
 * @return array
 */
public function getFlatIndexes()
{
 $indexes = array();
 $index = 'IDX_' . strtoupper($this->getAttribute()->getAttributeCode());
 $indexes[$index] = array(
 'type' => 'index',
 'fields' => array($this->getAttribute()->getAttributeCode())
 );
 return $indexes;
}
/**
 * Retrieve Select For Flat Attribute update
 *
 * @param int $store
 * @return Varien_Db_Select|null
 */
public function getFlatUpdateSelect($store)
{
 return Mage::getResourceModel('eav/entity_attribute')
 ->getFlatUpdateSelect($this->getAttribute(), $store);
}
/**
 * Get a text for index option value
 *
 * @param string|int $value
 * @return string|bool
 */
public function getIndexOptionText($value)
{
 switch ($value) {
 case self::VALUE_YES:
 return 'Yes';
 case self::VALUE_NO:
 return 'No';
 }
 return parent::getIndexOptionText($value);
}
answered Aug 28, 2015 at 15:20
1
  • The field uses one of the standard ones, so I'm pretty sure these methods are there. What I want to prevent is to re-index manually to build the flat tables again. Commented Sep 3, 2015 at 12:21

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.