Monday, September 1, 2014

Re: BelongsToMany model

I know what you mean but than i need to translate all my fields to show it to the users. Now i dont need to do anything the system generates the field and table names in my view in dutch because that is how my database model is build. Well it is solved now and i get what the problem is. Because the verzorgers table is not a problem and the key is searched for is verzorger. Because in english the s is for plural so he removes the s and knows that it is the singular form. Where can I find the core orm file in the system.

Met vriendelijke groet,
A. el Ibrahimi

Op 1 sep. 2014 12:56 schreef "Thomas von Hassel" <darxmac@gmail.com>:
Im not talking about what the users see, only what the models are called internally

/thomas


On 01 Sep 2014, at 12:55, Abdelmajid el Ibrahimi <a.elibrahimi@gmail.com> wrote:

I have used it but it still didnt solve the problem. And to make everything in english is double work for me because then i will need to translate everything. For a app that is only needed in holland.

Met vriendelijke groet,
A. el Ibrahimi

Op 1 sep. 2014 09:14 schreef "Thomas von Hassel" <darxmac@gmail.com>:
If you use $this->primaryKey($myKey) in your Table model, thats not in the core file and a perfectly valid to do.

But, i would mention that when designing your app, it's better to keep everything (model names etc) in english so the inflector knows how everything is named.

/thomas


On 01 Sep 2014, at 01:34, Abdelmajid el Ibrahimi <a.elibrahimi@gmail.com> wrote:

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:
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.


--
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 a topic in the Google Groups "CakePHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cake-php/lLkt9FpJLfg/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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.

--
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 a topic in the Google Groups "CakePHP" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cake-php/lLkt9FpJLfg/unsubscribe.
To unsubscribe from this group and all its topics, 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.

--
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: