2016-07-04 1 views
1

В моем действии рано у меня есть ответ вроде массива, но затем ответ меняется как объект, и я не понимаю, почему. Функция не findBitByProject изменить - вернутьSymfony RestBundle Аннотации Просмотр

$results = $query->getResult(); 

мое действие

$bits = $this->getDoctrine()->getManager() 
     ->getRepository('ArtelProfileBundle:Bit') 
     ->findBitByProject($request); 

    //$bits return array<Bit> 

    return View::create() 
     ->setStatusCode(200) 
     ->setData($bits) 
     ->setSerializationContext(
      SerializationContext::create() 
       ->setGroups(
        array('for_project_bit') 
       ) 
     ); 

ответ раннего

[ 
    {} 
    {} 
] 

Теперь

{ 
0: {} 
1: {} 
} 

моя ставка класс

/** 
* Bit. 
* 
* @ORM\Table(name="bit") 
* @ORM\HasLifecycleCallbacks 
* @ORM\Entity(repositoryClass="Artel\ProfileBundle\Entity\Repository\BitRepository") 
* @Gedmo\SoftDeleteable(fieldName="deletedAt") 
* @Annotation\ExclusionPolicy("all") 
*/ 
class Bit 
{ 
const NOT_APPROPRIATE  = 'not_appropriate'; 
const WAITING_FOR_DECISION = 'waiting_for_decision'; 
const CONFIRM    = 'confirmed'; 
const STATUS_SEND_CLIENT = 'send_client'; 
const WAITING_FOR_FEEDBACK = 'waiting_for_feedback'; 
const STATUS_SENT_CV  = 'sent_cv'; 
const STATUS_UNRESOLVED  = 'unresolved'; 

use Timestampable; 

/** 
* @var int 
* 
* @ORM\Column(name="id", type="integer") 
* @ORM\Id 
* @ORM\GeneratedValue(strategy="AUTO") 
* @Annotation\Expose() 
* @Annotation\Groups({ 
*  "get_client_by_id", "get_bid_id", "for_project_bit", "for_project_bit_admin", "for_all_projects", 
*  "get_entity_bits", "get_all_projects", "for_projects", "get_all_workorders", "get_workorder" 
* }) 
*/ 
private $id; 

/** 
* @var Developer 
* 
* @ORM\ManyToOne(targetEntity="Developer", inversedBy="bit", cascade={"persist"}) 
* @ORM\JoinColumn(name="developer_id", nullable = true, referencedColumnName="id") 
* @Annotation\Expose() 
* @Annotation\Groups({ 
*  "get_client_by_id", "get_bid_id", "for_project_bit", "for_project_bit_admin", "for_all_projects", "get_entity_bits", 
*  "for_projects", "get_all_projects" 
* }) 
*/ 
protected $developerId; 

/** 
* @var Users 
* 
* @ORM\ManyToOne(targetEntity="Users", inversedBy="bid", cascade={"persist"}) 
* @ORM\JoinColumn(name="author_id", nullable = true, referencedColumnName="id") 
* @Annotation\Expose() 
* @Annotation\Groups({ 
*  "get_client_by_id", "get_bid_id", "for_project_bit", "for_project_bit_admin", "for_all_projects", "get_entity_bits", 
*  "for_projects", "get_all_projects" 
* }) 
*/ 
protected $author; 

/** 
* @var Project 
* 
* @ORM\ManyToOne(targetEntity="Project", inversedBy="bit") 
* @ORM\JoinColumn(name="project_id", referencedColumnName="id", onDelete="CASCADE") 
* @Annotation\Expose() 
* @Annotation\Groups({"for_all_projects", "for_project_bit", "for_project_bit_admin", "get_entity_bits"}) 
*/ 
private $projectId; 

/** 
* @var float 
* 
* @Assert\NotBlank(groups={"post_bid"}) 
* @ORM\Column(name="rate", type="float") 
* @Annotation\Expose() 
* @Annotation\Groups({ 
*  "get_client_by_id", "get_bid_id", "for_projects", "for_project_bit", "for_project_bit_admin", 
*  "for_all_projects", "get_entity_bits" 
* }) 
*/ 
private $rate; 

когда я desable сериализатора группу для разработчиков отношения everythin ОК

почему это сложилось, со мной и как это исправить? :)

+0

пожалуйста показать ваш класс – LBA

+0

вопрос –

+0

обновления 'Бит' составляет $ бит, содержащие Bit или проекты с попутным Bit Collection? – LBA

ответ

0

Попробуйте следующее:

$view = View::create() 
    ->setStatusCode(200) 
    ->setData($bits) 
    ->setSerializationContext(
     SerializationContext::create() 
      ->setGroups(
       array('for_project_bit') 
      ) 
    ); 

return $this->handleView($view);