Nous avons un modèle de base de données qui ressemble à ceci:Joignez-vous à Propel provoque avertissement récursion
CREATE TABLE `Recipient` (
`username` VARCHAR(15),
`full_name` VARCHAR(45) NOT NULL,
`email` VARCHAR(50) NOT NULL,
`phone` VARCHAR(20) NOT NULL,
`status` BIT NOT NULL,
PRIMARY KEY (`username`)
) DEFAULT CHARSET=utf8;
CREATE TABLE `Printer` (
`id` INT(6) UNSIGNED AUTO_INCREMENT,
`arrival_date` DATETIME NOT NULL,
`archived_date` DATETIME,
`recipient_id` VARCHAR(15) NOT NULL,
FOREIGN KEY(`recipient_id`) REFERENCES Recipient(`username`),
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
CREATE TABLE `Owner` (
`id` INT(6) UNSIGNED AUTO_INCREMENT,
`name` VARCHAR(30) UNIQUE NOT NULL,
PRIMARY KEY (`id`)
) DEFAULT CHARSET=utf8;
CREATE TABLE `Document` (
`serial` VARCHAR(50),
`picture` TEXT,
`owner_id` int(6) UNSIGNED NOT NULL,
`printer_id` INT(6) UNSIGNED,
FOREIGN KEY(`owner_id`) REFERENCES Owner(`id`),
FOREIGN KEY(`printer_id`) REFERENCES Printer(`id`),
PRIMARY KEY(`serial`)
) DEFAULT CHARSET=utf8;
Lorsque nous appelons notre méthode get_printers
, qui ressemble à ceci:
public function get_printers(){
$printers = \PrinterQuery::create()
->joinWith("Document")
->useDocumentQuery()
->joinWith("Owner")
->endUse()
->joinWith("Recipient")
->find();
return $printers->toJSON();
}
nous obtenons ce que la réponse
{
"Printers": [
{
"Id": 1,
"ArrivalDate": null,
"ArchivedDate": null,
"RecipientId": "myusername",
"Recipient": {
"Username": "myusername",
"FullName": "Sture Testsson",
"Email": "[email protected]",
"Phone": "07383918",
"Status": "\u0001",
"Printers": [
"*RECURSION*"
]
},
"Documents": [
{
"Serial": "111",
"Picture": "url",
"OwnerId": 1,
"PrinterId": 1,
"Printer": "*RECURSION*"
},
{
"Serial": "222",
"Picture": null,
"OwnerId": 2,
"PrinterId": 1,
"Printer": "*RECURSION*"
},
{
"Serial": "333",
"Picture": null,
"OwnerId": 3,
"PrinterId": 1,
"Printer": "*RECURSION*"
}
]
}
]
}
question: Quelle est la cause du "Printer": "*RECURSION*"
, et comment pouvons-nous l'enlever de la réponse? De préférence sans avoir à SELECT
chaque colonne sauf les clés étrangères "distantes".
pourrait remplacer la méthode 'toJSON' et unset le champ de l'imprimante? – DarkBee