ORM - Doctrine

General discussion on PHP

ORM - Doctrine

Postby karim1 on Mon Dec 03, 2012 3:26 pm

Hi,
Givin this basics DB schema

create table accounts(
id int(11) auto increment,
name varchar(25),
deleted enum('1','0') default '0'
);

create table contacts(
id int(11) auto increment,
first_name varchar(25),
last_name varchar(25),
deleted enum('1','0') default '0'
);

create table accounts_contacts(
id int(11) auto increment,
id_account int(11),
id_contact int(11),
deleted enum('1','0') default '0'
);

select * from accounts
id | name | deleted
1 | ABC  | '0'

select * from contacts
id | first_name | last_name | deleted
1 | Tom  | Hanks | '0'
2 | Mel   | Gibson | '1'

select * from accounts_contacts
id | id_account | id_contact | deleted
1 | 1  | 1 | '0'
2 | 1  | 2 | '1'

and the entities :

/**
* @Entity @Table(name="accounts")
**/

class Account {

/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") **/
protected $id;

/**
* @ManyToMany(targetEntity="Contact")
* @JoinTable(name="accounts_contacts",
* joinColumns={@JoinColumn(name="id_account", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="id_contact", referencedColumnName="id")}
* )
*/
protected $contacts = null;

........
}

/**
* @Entity @Table(name="contacts")
**/

class Contact{

/** @Column(type="integer") @GeneratedValue **/
protected $id;

............
}

this command $account = $em->find("Account", 1);
will fetch the contact Mel Gibson, who's deleted

My question plz : how can i modify my entities , so the find command will fetch only not deleted contacts

thank you
karim1
 
Posts: 1
Joined: Mon Dec 03, 2012 3:13 pm

Re: ORM - Doctrine

Postby rstoll on Wed Dec 26, 2012 4:48 pm

if you are familiar with sql it is probably the easiest way to do it with dql - I cannot post the link but search for "doctrine query language"
rstoll
 
Posts: 5
Joined: Wed Dec 26, 2012 4:38 pm


Return to PHP

Who is online

Users browsing this forum: No registered users and 3 guests