我是Symfony2中的新成員,但我使用Rails。我願做這樣的事情在Symfony2中:Symfony2 + Doctrine vs Rails如何從相關表中檢索數據
class Manager < ActiveRecord::Base
has_many :employees
end
,問那麼對象是這樣的:
m = Manager.find(1)
# Sends SQL query SELECT COUNT * FROM EMPLOYEES WHERE MANAGER_ID = 1
count = m.employees.count
# Sends SQL query SELECT * FROM EMPLOYEES WHERE MANAGER_ID = 1
m.employees.each do |e|
puts e.name
end
我在Symfony2的驗證碼...
/**
* @Entity @Table(name="Manager")
*/
class Manager
{
/**
* @Id @Column(type="integer") @GeneratedValue
*/
public $id;
/**
* @Column(type="string")
*/
public $description;
/**
* @OneToMany(targetEntity="User", mappedBy="manager")
* @var User[]
*/
private $employees;
}
如何我可以在Symfony2中實現這些(上面的)功能嗎(ORR中容易實現的RoR)?
感謝您的幫助......
神話拉什