HI All,
This example will help you how to get products details of customer using restful API call,
your API call should like this :
http://127.0.0.1:8080/api/web/customer?expand=orders,orderItems,products
class Customer extends \yii\db\ActiveRecord
{
/**
* #inheritdoc
*/
public static function tableName()
{
return 'customer';
}
/**
* #inheritdoc
*/
public function rules()
{
return [
[['ID', 'Name'], 'required'],
[['ID'], 'integer'],
[['Name'], 'string'],
[['PhoneNo'], 'string', 'max' => 45]
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'ID' => 'ID',
'Name' => 'Name',
'PhoneNo' => 'Phone No',
];
}
/**
* #return \yii\db\ActiveQuery
*/
public function getOrders()
{
return $this->hasMany(Order::className(), ['customer_id' => 'ID']);
}
public function getOrderItems()
{
return $this->hasMany(Orderitem::className(),['Order_id' => 'ID' ])
->via('orders');
;
}
public function getProducts()
{
return $this->hasMany( Product::className() , ['ID' => 'Product_ID' ] )
->via('orderItems') ;
}
/**
* #inheritdoc
* #return CustomerQuery the active query used by this AR class.
*/
public static function find()
{
return new CustomerQuery(get_called_class());
}
/**
* #info: call : http://127.0.0.1:8080/api/web/customer?expand=orders for get customer and his orders also;
* #return type
*/
public function extraFields()
{
return ['orders','orderItems','products'];
}
}
Related
I got this code:
public function Locate($name){
$locate= Products::where('name', 'like', "$name%") ->get();
return response()->json($locate, 200);
}
I want to access belongsTo by this $name and put it in json
Here is my model:
class Products extends Model
{
protected $fillable = ['name', 'code', 'price'];
protected $hidden = ['id'];
public function Group()
{
return $this->belongsTo('App\pGroup', 'product_id', 'id');
}
}
If you want to get a relationship :
$locate= Products::where('name', 'like', "$name%")->with('group')->get();
I have taluka model where we select district and enter as many talukas.
But the records are not getting saved.
public function actionCreate()
{
$model = new Taluka();
if ($model->load(Yii::$app->request->post()) ) {
$talukaslist = $model->talukas;
if(is_array($talukaslist))
{
foreach($talukaslist as $taluka)
{
if($taluka ==null)
{
return $this->render('create', [
'model' => $model,
]);
}
else
if($taluka!=null)
{
$talukaRecord = new Taluka();
$talukaRecord->DistrictId = $model->DistrictId;
$talukaRecord->Taluka = $taluka;
$talukaRecord->save();
}
}
}
return $this->redirect(['index']);
}
else {
return $this->render('create', [
'model' => $model,
]);
}
}
If I use $talukaRecord->save(false), then the records are getting saved even if the validation fails.
Model:
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "taluka".
*
* #property integer $TalukaId
* #property integer $DistrictId
* #property string $Taluka
*
* #property Area[] $areas
* #property Colony[] $colonies
* #property Colonydemographic[] $colonydemographics
* #property District $district
* #property Village[] $villages
* #property Villagedemographic[] $villagedemographics
*/
class Taluka extends \yii\db\ActiveRecord
{
/**
* #inheritdoc
*/
public $talukas=[];
public static function tableName()
{
return 'taluka';
}
/**
* #inheritdoc
*/
public function rules()
{
return [
[['DistrictId', 'Taluka'], 'required'],
[['DistrictId'], 'integer'],
[['talukas'], 'required'],
[['Taluka'], 'string', 'max' => 100],
[['DistrictId'], 'exist', 'skipOnError' => true, 'targetClass' => District::className(), 'targetAttribute' => ['DistrictId' => 'DistrictId']],
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'TalukaId' => 'Taluka ID',
'DistrictId' => 'District',
'talukas' => 'Taluka',
];
}
/**
* #return \yii\db\ActiveQuery
*/
public function getAreas()
{
return $this->hasMany(Area::className(), ['TalukaId' => 'TalukaId']);
}
/**
* #return \yii\db\ActiveQuery
*/
public function getColonies()
{
return $this->hasMany(Colony::className(), ['TalukaId' => 'TalukaId']);
}
/**
* #return \yii\db\ActiveQuery
*/
public function getColonydemographics()
{
return $this->hasMany(Colonydemographic::className(), ['TalukaId' => 'TalukaId']);
}
/**
* #return \yii\db\ActiveQuery
*/
public function getDistrict()
{
return $this->hasOne(District::className(), ['DistrictId' => 'DistrictId']);
}
/**
* #return \yii\db\ActiveQuery
*/
public function getVillages()
{
return $this->hasMany(Village::className(), ['TalukaId' => 'TalukaId']);
}
/**
* #return \yii\db\ActiveQuery
*/
public function getVillagedemographics()
{
return $this->hasMany(Villagedemographic::className(), ['TalukaId' => 'TalukaId']);
}
}
Please try below code
public function actionCreate()
{
$model = new Taluka();
if ($model->load(Yii::$app->request->post()) ) {
$talukaslist = $model->talukas;
if(isset($talukaslist) && && $talukaslist!=array())
{
foreach($talukaslist as $taluka)
{
if(isset($taluka) && $taluka ==null)
{
return $this->render('create', [
'model' => $model,
]);
}
else
if(isset($taluka) && $taluka!=null)
{
$talukaRecord = new Taluka();
$talukaRecord->DistrictId = $model->DistrictId;
$talukaRecord->Taluka = $taluka;
if($talukaRecord->save())
{}
else
{
echo "<pre>";
print_r($talukaRecord->getErrors());die;
}
}
}
}
return $this->redirect(['index']);
}
else {
return $this->render('create', [
'model' => $model,
]);
}
}
Based on the https://github.com/wbraganca/yii2-dynamicform/wiki/Dynamic-Forms-With-Yii2-relation-trait-(VERY-EASY), I am trying to implement dynamic forms.Create is working perfect, but in Update form, if I delete any dynamic form element, it is not getting deleted, but If I add in the Update action, it is getting saved.
This is my Update code
public function actionUpdate($id)
{
$modelAlumni = $this->findModel($id);
$modelsJob = $modelAlumni->jobs;
if ($modelAlumni->loadAll(Yii::$app->request->post()) && $modelAlumni->saveAll()) {
return $this->redirect(['view', 'id' => $modelAlumni->id]);
} else {
return $this->render('update', [
'modelAlumni' => $modelAlumni,
'modelsJob' => (empty($modelsJob)) ? [new Job] : $modelsJob
]);
}
}
Why is it not deleting?
This is my Alumni model
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "alumni".
*
* #property integer $id
* #property string $name
* #property integer $gender
* #property integer $contact_number
* #property string $year_graduated
* #property string $qualification
* #property integer $department_id
* #property integer $specialization
* #property string $email
*
* #property Job[] $jobs
*/
class Alumni extends \yii\db\ActiveRecord
{
use \mootensai\relation\RelationTrait;
public $organization;
public $designation;
public $location;
public $current_status;
public $joining_date;
/**
* #inheritdoc
*/
public static function tableName()
{
return 'alumni';
}
/**
* #inheritdoc
*/
public function rules()
{
return [
[['name', 'gender', 'contact_number', 'year_graduated', 'qualification', 'department_id', 'specialization', 'email'], 'required'],
[['name', 'organization', 'designation', 'location'], 'string'],
[['gender', 'contact_number', 'department_id', 'specialization'], 'integer'],
[['year_graduated'], 'safe'],
[['qualification', 'email'], 'string', 'max' => 500],
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'name' => Yii::t('app', 'Name'),
'gender' => Yii::t('app', 'Gender'),
'contact_number' => Yii::t('app', 'Contact Number'),
'year_graduated' => Yii::t('app', 'Year Graduated'),
'qualification' => Yii::t('app', 'Qualification'),
'department_id' => Yii::t('app', 'Department ID'),
'specialization' => Yii::t('app', 'Specialization'),
'email' => Yii::t('app', 'Email'),
];
}
/**
* #return \yii\db\ActiveQuery
*/
public function getJobs()
{
return $this->hasMany(Job::className(), ['alumni_id' => 'id']);
}
}
Here is my Job Model
<?php
namespace app\models;
use Yii;
/**
* This is the model class for table "job".
*
* #property integer $job_id
* #property string $organization
* #property string $current_status
* #property string $designation
* #property string $joining_date
* #property string $location
* #property integer $alumni_id
*
* #property Alumni $alumni
*/
class Job extends \yii\db\ActiveRecord
{
/**
* #inheritdoc
*/
public static function tableName()
{
return 'job';
}
/**
* #inheritdoc
*/
public function rules()
{
return [
[['organization', 'current_status', 'designation', 'joining_date', 'location', 'alumni_id'], 'required'],
[['organization'], 'string'],
[['joining_date'], 'safe'],
[['alumni_id'], 'integer'],
[['current_status', 'designation'], 'string', 'max' => 300],
[['location'], 'string', 'max' => 255],
[['alumni_id'], 'exist', 'skipOnError' => true, 'targetClass' => Alumni::className(), 'targetAttribute' => ['alumni_id' => 'id']],
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'job_id' => Yii::t('app', 'Job ID'),
'organization' => Yii::t('app', 'Organization'),
'current_status' => Yii::t('app', 'Current Status'),
'designation' => Yii::t('app', 'Designation'),
'joining_date' => Yii::t('app', 'Joining Date'),
'location' => Yii::t('app', 'Location'),
'alumni_id' => Yii::t('app', 'Alumni ID'),
];
}
/**
* #return \yii\db\ActiveQuery
*/
public function getAlumni()
{
return $this->hasOne(Alumni::className(), ['id' => 'alumni_id']);
}
}
There is example, look at actionUpdate
https://github.com/wbraganca/yii2-dynamicform
first find All nested models ids that not in cuurrent POST request
$oldIDs = ArrayHelper::map($modelsAddress, 'id', 'id');
$modelsAddress = Model::createMultiple(Address::classname(), $modelsAddress);
Model::loadMultiple($modelsAddress, Yii::$app->request->post());
$deletedIDs = array_diff($oldIDs, array_filter(ArrayHelper::map($modelsAddress, 'id', 'id')));
then in transaction after save mainModel delete it:
if (! empty($deletedIDs))
{
Address::deleteAll(['id' => $deletedIDs]);
}
This is example, you have to implement for your own solution.
I think there is bug in relation-triat:
https://github.com/mootensai/yii2-relation-trait/issues/27
So above is the best solution
I retrieved the json response of a mailjet API in $ Data
class DefaultController extends FOSRestController {
/**
* #Rest\View()
* #Rest\Get("/apitest")
*/
public function indexAction()
{
$apikey = 'xxxxxxxxxxxxxxxxxxxxxxxxxxx';
$apisecret = 'xxxxxxxxxxxxxxxxxxxxxxxxxx';
$mj = new \Mailjet\Client($apikey, $apisecret);
$id=17361101;
$Data = $mj->get(Resources::$Message, ['id' => $id]);
$Data= $Data->getData();
return $Data;}
The Response Json:
[{"ArrivedAt":"2016-05-13T07:34:47Z","AttachmentCount":0,"AttemptCount":0,"CampaignID":4884268551,"ContactID":1690868613,"Delay":0,"DestinationID":12344543,"FilterTime":61,"ID":17361101,"IsClickTracked":true,"IsHTMLPartIncluded":true,"IsOpenTracked":true,"IsTextPartIncluded":false,"IsUnsubTracked":false,"MessageSize":19308,"SenderID":4294850021,"SpamassassinScore":0,"SpamassRules":"","StatePermanent":false,"Status":"clicked"}]
I created an entity message containing all the attributes of the Api response
<?php
namespace DashbordMailjetBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* #ORM\Entity
*/
class Message
{
/**
* #ORM\Column(type="datetime" ,name="ArrivedAt")
*/
private $ArrivedAt;
/**
* #ORM\Column(type="bigint",name="AttachmentCount")
*/
private $AttachmentCount;
/**
* #ORM\Column(type="bigint",name="AttemptCount")
*/
private $AttemptCount;
/**
* #ORM\Column(type="bigint",name="CampaignID")
*/
private $CampaignID;
/**
* #ORM\Column(type="bigint",name="ContactID")
*/
private $ContactID;
/**
* #ORM\Column(type="bigint",name="Delay")
*/
private $Delay;
/**
* #ORM\Column(type="bigint",name="DestinationID")
*/
private $DestinationID;
/**
* #ORM\Column(type="bigint",name="FilterTime")
*/
private $FilterTime;
/**
* #var bigint $uid
*
* #ORM\Column(name="id", type="bigint", nullable=false)
* #ORM\Id
* #ORM\GeneratedValue(strategy="IDENTITY")
*/
private $ID;
/**
* #ORM\Column(type="boolean",name="IsClickTracked")
*/
private $IsClickTracked;
/**
* #ORM\Column(type="boolean",name="IsHTMLPartIncluded")
*/
private $IsHTMLPartIncluded;
/**
* #ORM\Column(type="boolean",name="IsOpenTracked")
*/
private $IsOpenTracked;
/**
* #var boolean
*
* #ORM\Column(type="boolean",name="IsTextPartIncluded")
*/
private $IsTextPartIncluded;
/**
* #ORM\Column(type="boolean",name="IsUnsubTracked")
*/
private $IsUnsubTracked;
/**
* #ORM\Column(type="bigint",name="MessageSize")
*/
private $MessageSize;
/**
* #ORM\Column(type="bigint",name="SenderID")
*/
private $SenderID;
/**
* #ORM\Column(type="string",name="SpamassassinScore")
*/
private $SpamassassinScore;
/**
* #ORM\Column(type="string",name="SpamassRules", nullable=true)
*/
private $SpamassRules;
/**
* #ORM\Column(type="boolean",name="StatePermanent")
*/
private $StatePermanent;
/**
* #ORM\Column(type="string",name="Status")
*/
private $Status;
/**
* #return datetime
*/
public function getArrivedAt()
{
return $this->ArrivedAt;
}
/**
* #param datetime $ArrivedAt
*/
public function setArrivedAt($ArrivedAt)
{
$this->ArrivedAt = $ArrivedAt;
}
/**
* #return mixed
*/
public function getAttachmentCount()
{
return $this->AttachmentCount;
}
/**
* #param mixed $AttachmentCount
*/
public function setAttachmentCount($AttachmentCount)
{
$this->AttachmentCount = $AttachmentCount;
}
/**
* #return int
*/
public function getAttemptCount()
{
return $this->AttemptCount;
}
/**
* #param int $AttemptCount
*/
public function setAttemptCount($AttemptCount)
{
$this->AttemptCount = $AttemptCount;
}
/**
* #return int
*/
public function getCampaignID()
{
return $this->CampaignID;
}
/**
* #param int $CampaignID
*/
public function setCampaignID($CampaignID)
{
$this->CampaignID = $CampaignID;
}
/**
* #return int
*/
public function getContactID()
{
return $this->ContactID;
}
/**
* #param int $ContactID
*/
public function setContactID($ContactID)
{
$this->ContactID = $ContactID;
}
/**
* #return int
*/
public function getDelay()
{
return $this->Delay;
}
/**
* #param int $Delay
*/
public function setDelay($Delay)
{
$this->Delay = $Delay;
}
/**
* #return int
*/
public function getDestinationID()
{
return $this->DestinationID;
}
/**
* #param int $DestinationID
*/
public function setDestinationID($DestinationID)
{
$this->DestinationID = $DestinationID;
}
/**
* #return int
*/
public function getFilterTime()
{
return $this->FilterTime;
}
/**
* #param int $FilterTime
*/
public function setFilterTime($FilterTime)
{
$this->FilterTime = $FilterTime;
}
/**
* #return mixed
*/
public function getID()
{
return $this->ID;
}
/**
* #param mixed $ID
*/
public function setID($ID)
{
$this->ID = $ID;
}
/**
* #return boolean
*/
public function isIsClickTracked()
{
return $this->IsClickTracked;
}
/**
* #param boolean $IsClickTracked
*/
public function setIsClickTracked($IsClickTracked)
{
$this->IsClickTracked = $IsClickTracked;
}
/**
* #return boolean
*/
public function isIsHTMLPartIncluded()
{
return $this->IsHTMLPartIncluded;
}
/**
* #param boolean $IsHTMLPartIncluded
*/
public function setIsHTMLPartIncluded($IsHTMLPartIncluded)
{
$this->IsHTMLPartIncluded = $IsHTMLPartIncluded;
}
/**
* #return boolean
*/
public function isIsOpenTracked()
{
return $this->IsOpenTracked;
}
/**
* #param boolean $IsOpenTracked
*/
public function setIsOpenTracked($IsOpenTracked)
{
$this->IsOpenTracked = $IsOpenTracked;
}
/**
* #return boolean
*/
public function isIsTextPartIncluded()
{
return $this->IsTextPartIncluded;
}
/**
* #param boolean $IsTextPartIncluded
*/
public function setIsTextPartIncluded($IsTextPartIncluded)
{
$this->IsTextPartIncluded = $IsTextPartIncluded;
}
/**
* #return boolean
*/
public function isIsUnsubTracked()
{
return $this->IsUnsubTracked;
}
/**
* #param boolean $IsUnsubTracked
*/
public function setIsUnsubTracked($IsUnsubTracked)
{
$this->IsUnsubTracked = $IsUnsubTracked;
}
/**
* #return int
*/
public function getMessageSize()
{
return $this->MessageSize;
}
/**
* #param int $MessageSize
*/
public function setMessageSize($MessageSize)
{
$this->MessageSize = $MessageSize;
}
/**
* #return int
*/
public function getSenderID()
{
return $this->SenderID;
}
/**
* #param int $SenderID
*/
public function setSenderID($SenderID)
{
$this->SenderID = $SenderID;
}
/**
* #return string
*/
public function getSpamassassinScore()
{
return $this->SpamassassinScore;
}
/**
* #param string $SpamassassinScore
*/
public function setSpamassassinScore($SpamassassinScore)
{
$this->SpamassassinScore = $SpamassassinScore;
}
/**
* #return string
*/
public function getSpamassRules()
{
return $this->SpamassRules;
}
/**
* #param string $SpamassRules
*/
public function setSpamassRules($SpamassRules)
{
$this->SpamassRules = $SpamassRules;
}
/**
* #return boolean
*/
public function isStatePermanent()
{
return $this->StatePermanent;
}
/**
* #param boolean $StatePermanent
*/
public function setStatePermanent($StatePermanent)
{
$this->StatePermanent = $StatePermanent;
}
/**
* #return string
*/
public function getStatus()
{
return $this->Status;
}
/**
* #param string $Status
*/
public function setStatus($Status)
{
$this->Status = $Status;
}}
I'am Trying to deserialize the api response in a message object
<?php
namespace DashbordMailjetBundle\Controller;
use DashbordMailjetBundle\Entity\Message;
use FOS\RestBundle\Controller\Annotations as Rest;
use FOS\RestBundle\Controller\FOSRestController;
use \Mailjet\Resources;
use JMS\Serializer\SerializerBuilder;
class DefaultController extends FOSRestController
{
/**
* #Rest\View()
* #Rest\Get("/apitest")
*/
public function indexAction()
{
$apikey = 'xxxxxxxxxxxxxxxxxxxx';
$apisecret = 'xxxxxxxxxxxxxxxxxxxxx';
$mj = new \Mailjet\Client($apikey, $apisecret);
$id=17361101;
$Data = $mj->get(Resources::$Message, ['id' => $id]);
$Data= $Data->getData();
$serializer = SerializerBuilder::create()->build();
$msg=$serializer->deserialize($Data, 'DashbordMailjetBundle\Entity \Message', 'json');
$em = $this->getDoctrine()->getManager();
$em->persist($msg);
return $msg;
}
But I have this error : Warning: json_decode() expects parameter 1 to be string, array given, Any help ?
{"error":{"code":500,"message":"Internal Server Error","exception": [{"message":"Warning: json_decode() expects parameter 1 to be string, array given","class":"Symfony\\Component\\Debug\\Exception\\ContextErrorException","trace":[{"namespace":"","short_class":"","class":"","type":"","function":"","file":"\/home\/chayma\/my_project_name\/vendor\/jms\/serializer\/src\/JMS\/Serializer\/JsonDeserializationVisitor.php","line":27,"args":[]},{"namespace":"Symfony\\Component\\Debug","short_class":"ErrorHandler","class":"Symfony\\Component\\Debug\\ErrorHandler","type":"->","function":"handleError","file":null,"line":null,"args":[["string","2"],["string","json_decode() expects parameter 1 to be string, array given"],["string","\/home\/chayma\/my_project_name\/vendor\/jms\/serializer\/src\/JMS\/Serializer\/JsonDeserializationVisitor.php"],["string","27"],["array",{"str":["array",[["array",{"ArrivedAt":["string","2016-05-13T07:34:47Z"],"AttachmentCount":["string","0"],"AttemptCount":["string","0"],"CampaignID":["string","4884268551"],"ContactID":["string","1690868613"],"Delay":["string","0"],"DestinationID":["string","12344543"],"FilterTime":["string","61"],"ID":["string","17361101"],"IsClickTracked":["boolean",true],"IsHTMLPartIncluded":["boolean",true],"IsOpenTracked":["boolean",true],"IsTextPartIncluded":["boolean",false],"IsUnsubTracked":["boolean",false],"MessageSize":["string","19308"],"SenderID":["string","4294850021"],"SpamassassinScore":["string","0"],"SpamassRules":["string",""],"StatePermanent":["boolean",false],"Status":["string","clicked"]}]]]}]]},
As said supra, the serializer is expecting a string, but, if I print the result of $Data->getData(), I get an array, such as the one below:
Array
(
[0] => Array
(
[ArrivedAt] => 2017-02-15T10:01:00Z
[AttachmentCount] => 0
[AttemptCount] => 0
[CampaignID] => 5946xxxxxx
[ContactID] => 1725xxxxxx
[Delay] => 0
[DestinationID] => 14
[FilterTime] => 111
[ID] => 16888626888xxxxxx
[IsClickTracked] =>
[IsHTMLPartIncluded] => 1
[IsOpenTracked] => 1
[IsTextPartIncluded] => 1
[IsUnsubTracked] =>
[MessageSize] => 2213
[SenderID] => 4863xxxxxx
[SpamassassinScore] => 0
[SpamassRules] =>
[StatePermanent] =>
[Status] => opened
)
)
I'd advise you to look at the repository of the PHP wrapper, or at the documentation for PHP users.
hAPI coding!
Disclaimer: Mailjet's employee here.
As defined in the serializer documentation, $serializer->deserialize() expects a string.
It seems that your $Data->getData(); returns an array. (that's what the error message is telling you ;D )
I have relation between two tables through third with extra row (s) like in this question
/** #Entity
*/
class Illness {
/** #Id #GeneratedValue #Column(type="integer") */
private $illness_id;
/** #Column(type="string") */
private $name;
/** #OneToMany(targetEntity="Illness_Symptom_Association", mappedBy="Illness") */
private $symptAssoc;
public function __construct()
{
$this->symptAssoc = new \Doctrine\Common\Collections\ArrayCollection();
}
public function setName($val)
{
$this->name = $val;
}
public function getName()
{
return $this->name;
}
public function getSymptAssoc()
{
return $this->symptAssoc;
}
}
Join table with third param s (something like priority)
/**
* #Entity
*/
class Illness_Symptom_Association {
protected $illness_id;
/**
* #Id()
* #ManyToOne(targetEntity="Illness", inversedBy="symptAssoc")
* #JoinColumn(name="illness_id", referencedColumnName="illness_id", nullable=false)
*/
protected $illness;
/**
* #Id()
* #ManyToOne(targetEntity="Symptom", inversedBy="symptAssoc")
* #JoinColumn(name="symptom_id", referencedColumnName="symptom_id")
* */
protected $symptom;
/** #Column(type="integer") */
protected $s;
public function setIllness(Illness $illness)
{
$this->illness = $illness;
}
/**
*
* #return Illness
*/
public function getIllness()
{
return $this->illness;
}
public function setSymptom(Symptom $sympt)
{
return $this->symptom = $sympt;
}
public function getSymptom()
{
return $this->symptom;
}
public function setS($s)
{
$this->s = $s;
}
public function getS()
{
return $this->s;
}
}
Last entity with symptoms:
/**
* #Entity
*/
class Symptom {
/** #Id #GeneratedValue #Column(type="integer") */
protected $symptom_id;
/** #Column(type="string", unique=true) */
protected $name;
/** #OneToMany(targetEntity="Illness_Symptom_Association", mappedBy="symptom") */
protected $symptAssoc;
public function setName($name)
{
$this->name = $name;
}
public function getName($name)
{
return $this->name;
}
}
But
$illness = $em->getRepository('Entity\Illness')->find($id);
$illness->getSymptAssoc();
return PersistentCollection oject.
How I can get list of symptoms with s param from join table?
A PersistentCollection is a Collection (of Symptom objects, in this case). It already is a list of symptoms.
You can iterate it (just like an array), access its elements (which are Symptom objects in this case), or convert it to an array:
$illness->getSymptAssoc()->toArray();