i just changed the key to leerlingen_id and it works. Just a workaround but i dont want to screw with the core files. CakePHP is supposed to be easy to use that means that if i follow the tutorial it should do what is says.
Op zondag 31 augustus 2014 21:35:59 UTC+2 schreef José Lorenzo:
-- Op zondag 31 augustus 2014 21:35:59 UTC+2 schreef José Lorenzo:
You also have control over what is the foreignKey to use when creating the association. Refer the the ORM docs to customize what the query builder is doing.
On Sunday, August 31, 2014 7:30:36 PM UTC+2, Abdelmajid el Ibrahimi wrote:But even if i take that out it still says the same.
Op zondag 31 augustus 2014 11:45:25 UTC+2 schreef José Lorenzo:There is no "public $primaryKey" in CakePHP 3.0
You may use $this->primaryKey($myKey) inside the initialize() method
On Sunday, August 31, 2014 3:54:56 AM UTC+2, Abdelmajid el Ibrahimi wrote:I have made two tables leerlingen and verzorgers. Because these have a many to many relation i added a table leerlingen_verzorgers.
I have added 3 model tables:
class VerzorgersTable extends Table {
public $primaryKey = 'verzorger_id';
public function initialize(array $config) {
$this->belongsToMany('Leerlingen',
['through' => 'LeerlingenVerzorgers',]);
$this->addBehavior('Timestamp');
}
}
class LeerlingenTable extends Table {
public $primaryKey = 'leerling_id';
public function initialize(array $config) {
$this->belongsToMany('Verzorgers',
['through' => 'LeerlingenVerzorgers',]);
$this->addBehavior('Timestamp');
}
}
class LeerlingenVerzorgersTable extends Table {
public function initialize(array $config) {
$this->belongsTo('Leerlingen');
$this->belongsTo('Verzorgers');
}
}
Now when i want to retrieve a verzorger with all the leerlingen i get an error that he doesn't know the leerlingen_id this is right because it is leerling_id. But with the verzorgers table he does use the right id and asks for the verzorger_id.
My relation table looks like this:
leerlingen_verzorgers
--------------------------
id
leerling_id
verzorgers_id
jaar
The generated query looks like this:'SELECT Leerlingen.leerling_id AS `Leerlingen__leerling_id`, Leerlingen.voornaam AS `Leerlingen__voornaam`, Leerlingen.achternaam AS `Leerlingen__achternaam`, Leerlingen.geboortedatum AS `Leerlingen__geboortedatum`, Leerlingen.geslacht AS `Leerlingen__geslacht`, Leerlingen.email AS `Leerlingen__email`, Leerlingen.opmerking AS `Leerlingen__opmerking`, LeerlingenVerzorgers.id AS `LeerlingenVerzorgers__id`, LeerlingenVerzorgers.leerling_id AS `LeerlingenVerzorgers__ leerling_id`, LeerlingenVerzorgers. verzorger_id AS `LeerlingenVerzorgers__ verzorger_id`, LeerlingenVerzorgers.jaar AS `LeerlingenVerzorgers__jaar` FROM leerlingen AS Leerlingen INNER JOIN leerlingen_verzorgers LeerlingenVerzorgers ON (LeerlingenVerzorgers. verzorger_id IN (:c0) AND Leerlingen.leerling_id = (LeerlingenVerzorgers. leerlingen_id))
so first he uses the right leerling_id but at the end he uses leerlingen_id. Anyone knows what i did wrong?
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment