I have a custom module with named A and db tab is z ok. now question is my:

  1. How to add child table? which is already I have done with PK and FK key constrains.

  2. How to add data in created child table using model?

  • what you have tried so far?
    – Amit Bera
    Feb 10, 2022 at 17:45

1 Answer 1


Please follow the below code.

    protected $_orderTemplate;
    protected $_orderTemplateItem;
    public function __construct(
        \Bhavesh\OrderTemplate\Model\OrderTemplate $orderTemplate,
        \Bhavesh\OrderTemplate\Model\OrderTemplateItem $orderTemplateItem,
    ) {
        $this->_orderTemplate = $orderTemplate;
        $this->_orderTemplateItem = $orderTemplateItem;

   public function execute()
         // Parent table
          $template_name = $templateName."-".date('M Y');
           // parent table id    
          $templateID = $orderTemplateModel->getTemplateId();
          // Child Table store in Product data   
          $orderTemplateItemModel = $this->_orderTemplateItem;

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.