Code Monkey home page Code Monkey logo

Comments (6)

mareksuscak avatar mareksuscak commented on May 27, 2024

Let me know if you need a minimum reproducible example. I can put something together but had to significantly simplify the above classes because it comes from a fairly complex app with many more properties. I was hoping that it might be an obvious use case to replicate and fix.

from mikro-orm.

B4nan avatar B4nan commented on May 27, 2024

Let me know if you need a minimum reproducible example

I always need one :)

@manytoone(() => PageRevision, {
primary: true,
fieldName: 'page_revision_id',
onUpdate: () => 'cascade',
onDelete: 'cascade',
})
pageRevision: PageRevision;

This is surely wrong, and won't even compile in v6. onUpdate: () => 'cascade' means you update the value to a string cascade every time, and in v6 onDelete is renamed to deleteRule. Which brings me to a question, are you really on v6? And did you really reproduce with such entities?

So yes, complete repro needed, because this is suspicious on its own.

from mikro-orm.

mareksuscak avatar mareksuscak commented on May 27, 2024

Yes, we are on v6 and yes it does compile. I'll put together a repro.

CleanShot 2024-03-08 at 10 45 52@2x

from mikro-orm.

B4nan avatar B4nan commented on May 27, 2024

Yes, we are on v6 and yes it does compile.

Your screenshot is not the same as what you have put into the issue description. Note the deleteRule (on screenshot) vs onDelete (in the issue).

And either way, what I said above about the onUpdate is correct too, using onUpdate: () => 'cascade' is wrong, you want updateRule: 'cascade'.

from mikro-orm.

mareksuscak avatar mareksuscak commented on May 27, 2024

Sorry, I simplified the entities and I must have based them on a different branch or something. What's in the screenshot is right.

from mikro-orm.

B4nan avatar B4nan commented on May 27, 2024

Here is a passing repro, let's reopen with a failing one:

import { Entity, MikroORM, Property, ManyToOne, Collection, ManyToMany, Formula, PrimaryKey } from '@mikro-orm/sqlite';
import { mockLogger } from '../../helpers';

@Entity()
class User {

  @PrimaryKey()
  id!: number;

  @Property({ nullable: true })
  firstName?: string;

  @Property({ nullable: true })
  lastName?: string;

  @Property({ nullable: true })
  email?: string;

  @Formula(alias => `CONCAT(${alias}.first_name, ' ', ${alias}.last_name)`)
  fullName?: string;

  @Formula(alias => `LOWER(${alias}.email)`)
  emailLower?: string;

}

@Entity()
class PageRevision {

  @PrimaryKey()
  id!: number;

  @ManyToMany({
    entity: () => User,
    pivotEntity: () => PageRevisionUser,
  })
  users = new Collection<User>(this);

}

@Entity()
class PageRevisionUser {

  @ManyToOne(() => PageRevision, { primary: true })
  pageRevision!: PageRevision;

  @ManyToOne(() => User, { primary: true })
  user!: User;

}

let orm: MikroORM;

beforeAll(async () => {
  orm = await MikroORM.init({
    dbName: ':memory:',
    entities: [PageRevision, User, PageRevisionUser],
    debug: true,
  });
  await orm.schema.refreshDatabase();
});

afterAll(async () => {
  await orm.close(true);
});

test('GH #5319', async () => {
  const mock = mockLogger(orm);
  await orm.em.findAll(PageRevision, { populate: ['users'] });
  expect(mock.mock.calls[0][0]).toMatch('select `p0`.*, `u1`.`id` as `u1__id`, `u1`.`first_name` as `u1__first_name`, `u1`.`last_name` as `u1__last_name`, `u1`.`email` as `u1__email`, CONCAT(`u1`.first_name, \' \', `u1`.last_name) as `u1__full_name`, LOWER(`u1`.email) as `u1__email_lower` ' +
    'from `page_revision` as `p0` ' +
    'left join `page_revision_user` as `p2` on `p0`.`id` = `p2`.`page_revision_id` ' +
    'left join `user` as `u1` on `p2`.`user_id` = `u1`.`id`');
});

from mikro-orm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.