0

I sent this question some days ago:

"I'm using the module Ultimate Module Creator to create new entities and relate them to products, categories and between them.

But I don't know how to relate the entities to themselves. I can't do it with the module. How I could create this type of relation without the module? "

0

And I've solved it with Ultimate Module Creator:

1# I've created the entity called Looks that I want to relate with itself

2# To relate an entity wit itself, I only need a table with two columns (look_id, linked_look_id). So, I've created other entity called Related, and Looks is parent of Related. Therefore, I have the first column (look_id) in the table. Then, I've created other attribute called linked_look_id. Type: dropdown, to select the look. And now comes the trick!! I've selected Source: Manually defined, and I've assigned it any values.And now comes the trick!! I've selected Source: Manually defined, and I've assigned it any values. But then I've modified the code (see step3) enter image description here

3# I've modified the file Namespace/Looks/Model/Related/Attribute/Source/Linkedlookid.php and now the function getAllOptions return the values of the entity Looks.

public function getAllOptions($withEmpty = true, $defaultValues = false)
{
      if (is_null($this->_options)) {
          $this->_options = Mage::getResourceModel('namespace_looks/look_collection')

          ->load()
          ->toOptionArray();
      }
      $options = $this->_options;
      if ($withEmpty) {
          array_unshift($options, array('value'=>'', 'label'=>''));
      }
      return $options;

}

enter image description here

Now in the form, I can select the one look and related look.

I hope it helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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