dò una prova a rispondere alla mia domanda, io sono ancora abbastanza sfocatura con questo, spero che qualcuno può davvero dare una risposta migliore,
così prima di rispondere alla domanda circa come faccio derivo con $friendsWithMe
in pratica, ho iniziato con "decodifica" una relazione più semplice, più comune, da molti a molti bidirezionale.
- 1 utente può essere in molti gruppi
- 1 gruppo può avere molti utenti
molto dritto in avanti. ma come ha senso questo in SQL?

codice per implementare
# select groups user is in
select group_id from users_groups
where user_id = 1
#select users of group
select user_id from users_groups
where group_id = 1
ora al modello attuale ... in SQL

nel codice
# select friends of given user
# $user->myFriends
select friend_id from friends
where user_id = 1;
# select users that are friends of given user
# $user->friendsWithMe
select user_id from friends
where friend_id = 1;
ah ah! seleziona gli utenti amici di un determinato utente. quindi questo è il modo in cui ottengo $friendsWithMe
. quindi per riempire il inversedBy
& mappedBy
& il resto della classe?
primo sguardo alla nota in basso.

non è chiaro, senza tanto e profondità di pensiero, circa 2 giorni. credo che
quindi come pratica come faccio a creare una relazione di auto-referenziamento da molti a molti?
l'esempio su cui sto andando a lavorare è ... hmm, piuttosto schifoso penso ma, proverò :) ... 1 utente/studente può avere molti insegnanti. 1 insegnante può avere molti utenti/studenti. 1 utente può essere un insegnante e uno studente qui. Sai come nei forum come questi, quando rispondi alle domande di qualcuno, sei un insegnante. quando u chiedere, u sono uno studente
il disco di ripristino sarà simile

po 'di codice per selezionare, gli studenti di insegnanti, insegnanti di studenti
# select students of teacher
# $teacher->students
select student from teacher_student
where teacher = 1;
# select teachers of student
# $student->teachers
select teacher from teacher_student
where student = 2;
ok, la parte dottrina ?
/** @Entity @Table(name="users")) */
class User {
/**
* @Id @Column(type="integer")
* @GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @Column(type="string", length="30")
*/
private $name;
/**
* @ManyToMany(targetEntity="User", inversedBy="teachers")
* @JoinTable(name="Teachers_Students",
* joinColumns={@JoinColumn(name="teacher", referencedColumnName="id")},
* inverseJoinColumns={@JoinColumn(name="student", referencedColumnName="id")}
* )
*/
private $students;
/**
* @ManyToMany(targetEntity="User", mappedBy="students")
*/
private $teachers;
}
che ha generato questa tavoli per me
# users
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
#teachers_students
CREATE TABLE `teachers_students` (
`teacher` int(11) NOT NULL,
`student` int(11) NOT NULL,
PRIMARY KEY (`teacher`,`student`),
KEY `student` (`student`),
CONSTRAINT `teachers_students_ibfk_2` FOREIGN KEY (`student`) REFERENCES `users` (`id`),
CONSTRAINT `teachers_students_ibfk_1` FOREIGN KEY (`teacher`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1
finalmente ho fatta! lascia testarlo ... ehm sto ottenendo
Fatal error: Class 'Entities\User' not found in D:\ResourceLibrary\Frameworks\Doctrine\tools\sandbox\index.php on line 61
quando provo a fare uno zzz
$user = new User;
...
inoltre ho bloggato circa questa domanda e la mia spiegazione sul mio tumblr
$ user = new User(); – ruipacheco
+1 Per chiarezza di domande e sforzi nella preparazione di materiale sorgente aggiuntivo – calumbrodie
Ciao. Ho avuto problemi con la dottrina con queste relazioni. Quando aggiungo elementi a quel tipo di raccolta, svuota e dopo li rimuovo tutti e faccio di nuovo flush Sto ricevendo 'La classe 'Doctrine \ ORM \ Persisters \ ManyToManyPersister' non è stata trovata negli spazi dei nomi chain configurati'. Quando rimuovo gli oggetti, ma ne esco almeno uno tutto funziona perfettamente. Puoi testare questo comportamento per me? e se non ricevi alcun problema pubblica la versione della dottrina che stai utilizzando? Sarò grato. –