This topic contains 5 replies, has 1 voice, and was last updated by Rodolfo 7 years, 11 months ago.
- Topic
Hello Oro Community,
My problem today is making a RESTful Api working with custom entities and relations Many-To-One.
1) This is what I have in Account entity. As you can see, I have @ORM\Id on my $originalEmail field.
12345678910111213141516171819202122232425262728293031323334/*** @var integer** @ORM\Column(name="id", type="integer")* @ORM\GeneratedValue(strategy="AUTO")* @ConfigField(* defaultValues={* "entity"={* "label"="id",* "plural_label"="ids",* "description"="id"* }* }* )*/protected $id;/*** @var string** @ORM\Column(name="original_email", type="string")* @ORM\Id* @ConfigField(* defaultValues={* "entity"={* "label"="Original Email",* "plural_label"="Original Emails",* "description"="Original Emails"* }* }* )*/protected $originalEmail;2) In Orders entity, as you can see, I created the relation Many-To-One (Multiple orders per Account and created the reference to my “original_email”.
12345678910111213141516/*** @var MyAccounts** @ORM\ManyToOne(targetEntity="Acme\Bundle\MyBundle\Entity\MyAccounts")* @ORM\JoinColumn(name="original_email", referencedColumnName="original_email", onDelete="SET NULL", nullable=true)* @ConfigField(* defaultValues={* "entity"={* "label"="Original Email",* "plural_label"="Original Email",* "description"="Original Email"* }* }* )*/protected $originalEmail;3) On my Orders Form Type, I have this inside my buildForm method:
123456789->add('originalEmail','translatable_entity',['class' => 'Acne\Bundle\MyBundle\Entity\MyAccounts','property' => 'original_email','required' => true])4) Inside my OrdersApiController I have my postAction() method using the Oro Abstraction layer to perform the insert.
1234public function postAction(){return $this->handleCreateRequest();}All RESTful methos for Acconts works fine. The problem is to use RESTful on Orders entity. Looks like
there is something wrong with my “originalEmail” field.So I’m trying to insert orders using this structure:
123456789$response = $oroClient->post('api/rest/latest/mybundle/orders.json', ['body' => [.........'originalEmail' => 'example@example.org','owner' => '1', // OroCRM User ID]]);And the error is:
…………,”originalEmail”:{“errors”:[“This value is not valid.”]}}}}………..
Do you see something wrong or something that could be improved on my code?
Thank you!
The forum ‘OroPlatform – Programming Questions’ is closed to new topics and replies.