Forums › Forums › OroCRM › OroCRM – Programming Questions › Insert Data into DB with persist
This topic contains 6 replies, has 3 voices, and was last updated by Yevhen Shyshkin 9 years, 11 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- April 28, 2014 at 6:13 am #24747
Hi, I’ve a littre problem. I want add to my DB an object Invoice.
12345678910111213141516$invoice_obj = new Invoice();//Initialization of all fields$invoice_obj->setTitle($invoice->title);$invoice_obj->setInvoicedOn($invoice->invoiced_on);$invoice_obj->setIsActiveReminder(true);$invoice_obj->setTermOn($invoice->term_on);$invoice_obj->setTotalHT($invoice->total);$invoice_obj->setTotalTTC($invoice->total_with_vat);$invoice_obj->setAccountId(null);$invoice_obj->setPaidOn(null);$em = $this->getDoctrine()->getManager();$em->persist($invoice_obj);$em->flush();And my Entity Invoice, I use account_id (reference to Oro Account Bundle) :
123456/*** @var \OroCRM\Bundle\AccountBundle\Entity\Account*/private $account_id;My problem is when I want add to my DB, I’ve an error.
I can’t add my new object.If you are an idea, thank you.
- CreatorTopic
- AuthorReplies
- April 28, 2014 at 6:20 am #24748
Important:
I have a Bundle Invoice and a Bundle Local where I make all my works. I want send into my DB my new Object Invoice (in the Local Bundle).
April 28, 2014 at 10:14 am #24749Can you please post the error message and Invoice entity definition?
April 29, 2014 at 1:33 am #24750Hi, my Invoice entity :
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326<?phpnamespace Relance\Bundle\InvoiceBundle\Entity;use Doctrine\ORM\Mapping as ORM;/*** Invoice*/class Invoice{/*** @var integer*/private $id;/*** @var string*/private $title;/*** @var integer*/private $total_HT;/*** @var integer*/private $total_TTC;/*** @var \DateTime*/private $invoiced_on;/*** @var \DateTime*/private $term_on;/*** @var \DateTime*/private $paid_on;/*** @var boolean*/private $isActiveReminder;/*** @var \OroCRM\Bundle\AccountBundle\Entity\Account*/private $account_id;/*** @var \Doctrine\Common\Collections\Collection*/private $letters;/*** @var integer*/private $external_id;/*** Constructor*/public function __construct(){$this->letters = new \Doctrine\Common\Collections\ArrayCollection();}/*** Get id** @return integer*/public function getId(){return $this->id;}/*** Set title** @param string $title* @return Invoice*/public function setTitle($title){$this->title = $title;return $this;}/*** Get title** @return string*/public function getTitle(){return $this->title;}/*** Set total_HT** @param integer $totalHT* @return Invoice*/public function setTotalHT($totalHT){$this->total_HT = $totalHT;return $this;}/*** Get total_HT** @return integer*/public function getTotalHT(){return $this->total_HT;}/*** Set total_TTC** @param integer $totalTTC* @return Invoice*/public function setTotalTTC($totalTTC){$this->total_TTC = $totalTTC;return $this;}/*** Get total_TTC** @return integer*/public function getTotalTTC(){return $this->total_TTC;}/*** Set invoiced_on** @param \DateTime $invoicedOn* @return Invoice*/public function setInvoicedOn($invoicedOn){$this->invoiced_on = $invoicedOn;return $this;}/*** Get invoiced_on** @return \DateTime*/public function getInvoicedOn(){return $this->invoiced_on;}/*** Set term_on** @param \DateTime $termOn* @return Invoice*/public function setTermOn($termOn){$this->term_on = $termOn;return $this;}/*** Get term_on** @return \DateTime*/public function getTermOn(){return $this->term_on;}/*** Set paid_on** @param \DateTime $paidOn* @return Invoice*/public function setPaidOn($paidOn){$this->paid_on = $paidOn;return $this;}/*** Get paid_on** @return \DateTime*/public function getPaidOn(){return $this->paid_on;}/*** Set isActiveReminder** @param boolean $isActiveReminder* @return Invoice*/public function setIsActiveReminder($isActiveReminder){$this->isActiveReminder = $isActiveReminder;return $this;}/*** Get isActiveReminder** @return boolean*/public function getIsActiveReminder(){return $this->isActiveReminder;}/*** Set account_id** @param \OroCRM\Bundle\AccountBundle\Entity\Account $accountId* @return Invoice*/public function setAccountId(\OroCRM\Bundle\AccountBundle\Entity\Account $accountId = null){$this->account_id = $accountId;return $this;}/*** Get account_id** @return \OroCRM\Bundle\AccountBundle\Entity\Account*/public function getAccountId(){return $this->account_id;}/*** Add letters** @param \Relance\Bundle\LetterBundle\Entity\Letter $letters* @return Invoice*/public function addLetter(\Relance\Bundle\LetterBundle\Entity\Letter $letters){$this->letters[] = $letters;return $this;}/*** Remove letters** @param \Relance\Bundle\LetterBundle\Entity\Letter $letters*/public function removeLetter(\Relance\Bundle\LetterBundle\Entity\Letter $letters){$this->letters->removeElement($letters);}/*** Get letters** @return \Doctrine\Common\Collections\Collection*/public function getLetters(){return $this->letters;}/*** Set external_id** @param integer $externalId* @return Invoice*/public function setExternalId($externalId){$this->external_id = $externalId;return $this;}/*** Get external_id** @return integer*/public function getExternalId(){return $this->external_id;}}The error message is:
1Error! Incorrect server response. Debug:That’s all.
April 30, 2014 at 2:10 am #24751Hello, ruizalexandre.
1) First you have to set Doctrine ORM annotations for entity and fields – @ORM/Table and @ORM/Entity for class, and @ORM\Id, @ORM\Column etc. for fields (see https://github.com/orocrm/crm/blob/master/src/OroCRM/Bundle/SalesBundle/Entity/Lead.php).
2) Then you can try to update your DB. To test that execute command `php app/console doctrine:schema:update –dump-sql` – it should show you SQL that creates DB table, and if it’s ok – `php app/console doctrine:schema:update –force` to execute SQL. You have to remember that this is ok only for debug – in any case you’ll need to add migration to create this entity.
3) Ensure that your DB really contains table for your entity. You can either use UI DB manager, or do it from CLI.
Try to do that – if you’ll still have an error – please, put it here.
In general to generate DB entities I’d recommend to use command `php app/console generate:doctrine:entity` – it will add all required fields and annotations automatically.
May 5, 2014 at 2:12 am #24752Hi, I’ve made updates into my code. But I’ve the same error message.
1Error! Incorrect server response. Debug:123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990/*** Invoice** @ORM\Table(name="relance_invoice")* @ORM\Entity*/class Invoice{/*** @var integer** @ORM\Column(name="id", type="integer")* @ORM\Id* @ORM\GeneratedValue(strategy="AUTO")*/private $id;/*** @var string** @ORM\Column(name="title", type="string", length=255, nullable=false)*/private $title;/*** @var integer** @ORM\Column(name="total_HT", type="integer", nullable=false)*/private $total_HT;/*** @var integer** @ORM\Column(name="total_TTC", type="integer", nullable=false)*/private $total_TTC;/*** @var \DateTime** @ORM\Column(type="datetime")*/private $invoiced_on;/*** @var \DateTime** @ORM\Column(type="datetime")*/private $term_on;/*** @var \DateTime** @ORM\Column(type="datetime", nullable=true)*/private $paid_on;/*** @var boolean** @ORM\Column(name="isActiveReminder", type="boolean", nullable=true, options={"default":true})*/private $isActiveReminder;/*** @var \OroCRM\Bundle\AccountBundle\Entity\Account** @ORM\ManyToOne(targetEntity="Oro\Bundle\AccountBundle\Entity\Account", cascade={"persist", "remove"})* @ORM\JoinColumn(name="id", referencedColumnName="id", onDelete="SET NULL", nullable=true)*/private $account_id;/*** @var \Relance\Bundle\LetterBundle\Entity\Letter** @ORM\OneToMany(targetEntity="Relance\Bundle\LetterBundle\Entity\Letter", mappedBy="invoice")*/private $letters;/*** @var integer** @ORM\Column(name="external_id", type="integer", nullable=false)*/private $external_id;An idea?
May 5, 2014 at 3:15 am #24753Could you, please, do the same in dev mode and put here full error text with backtrace?
Also you can found your errors in /app/logs/dev.log or /app/logs/prod.log. - AuthorReplies
The forum ‘OroCRM – Programming Questions’ is closed to new topics and replies.