ikkez / f3-cortex

A multi-engine ORM / ODM for the PHP Fat-Free Framework
GNU General Public License v3.0
118 stars 22 forks source link

Many to Many doesn't work with own relfield #107

Open adkurz opened 4 years ago

adkurz commented 4 years ago

With latest commit (master) and with v1.7, there is a problem with many to many relations with the experimental new column names. The ugly table looks like this (german field names):

table rechtehg (
id int,
bid int,
hgid int
)

bid means user id, hgid means main group id In Cortex model, fieldconf looks like this: Model User:

'berechtigte_hauptgruppen' => [
  'has-many' => ['\Model\MainGroup', 'berechtigte_benutzer', 'rechtehg'],
  'relField' => 'bid'
]

Model MainGroup:

  'berechtigte_benutzer' => [
  'has-many' => ['\Model\User', 'berechtigte_hauptgruppen', 'rechtehg'],
  'relField' => 'hgid'
]

But if I use the relation, for example with a contains it doesn't work:

$mainGroup = new \Model\MainGroup();
$mainGroup->virtual(
  'selected',
  function ($self) use ($user) {
    if (is_null($self->berechtigte_benutzer))
      return false;
    return $self->berechtigte_benutzer->contains($user);
  }
);
$list = $mainGroup->find();

Cortex generates following wrong sql statement:

SELECT "id","bid","hgid" FROM "rechtehg" WHERE "berechtigte_hauptgruppen" IN ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12)

The column name after the "where" does not exist, it should be hgid or bid. System: Postgresql 11, Debian 10, php 7.4fpm, F3 7.2.

ikkez commented 3 years ago

I just checked that once more and was not able to reproduce the issue.. looks good to me with the same setup