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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.