How to submit form values ​​in 2 different symfony tables

I want to submit a form and save the values ​​in two different tables (which are in the same database).

This is the form:

<div class="control-group">
      <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>Naam</label>

      <div class="controls">
            {{ form_widget(form.product) }}
            {{ form_errors(form.product) }}
      </div>
</div>
<div class="control-group">
      <label{% for attrname,attrvalue in attr %} {{attrname}}="{{attrvalue}}"{% endfor %}>Aantal</label>

      <div class="controls">
           {{ form_widget(form.amount) }}
           {{ form_errors(form.amount) }}
      </div>
</div>

This is a form builder:

$builder->add("amount", "number", array("label" => "Aantal"));
$builder->add("product", "text", array("attr" => array("autocomplete" => "off", "data-provide" => "typeahead", "data-items" => "15", "data-source" => $dataSource), 'mapped' => false));
$builder->add("price", "number", array("label" => "Aangepaste prijs", 'mapped' => false));

this is part of the object:

/**
     * @var integer $id
     */
    private $id;

    /**
     * @var integer $amount
     */
    private $amount;

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }

    /**
     * Set amount
     *
     * @param integer $amount
     * @return BookingEntry
     */
    public function setAmount($amount)
    {
        $this->amount = $amount;

        return $this;
    }

    /**
     * Get amount
     *
     * @return integer 
     */
    public function getAmount()
    {
        return $this->amount;
    }

and here is the ORM:

type: entity
    table: null
    fields:
        id:
            type: integer
            id: true
            generator:
                strategy: AUTO
        amount:
            type: float

Now I want to add an input field in the form named "serial_nr". I want to keep this value in a different table than where the "product" and "sum" are stored.

Can someone point me in the right direction?

+4
source share
1 answer

"product" "price" "mapped" = > false, , , , . , () :

(product_serial) :

  • product_id
  • serial_nr

? , product_serial:

manyToOne:
    product:
        targetEntity: Product
        inversedBy: serials
        joinColumn:
            name: product_id
            referencedColumnName: id

:

oneToMany:
    serials:
        targetEntity: ProductSerial
        mappedBy: product

"".

http://symfony.com/doc/current/reference/forms/types/collection.html

+1

Source: https://habr.com/ru/post/1615532/


All Articles