Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
adkurz opened this issue Sep 1, 2020 · 1 comment
Open

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

adkurz opened this issue Sep 1, 2020 · 1 comment

Comments

@adkurz
Copy link

adkurz commented Sep 1, 2020

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
Copy link
Owner

ikkez commented Feb 17, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants