Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Bnaya Peretz
    @Bnaya
    My current direction is to just declare "one to many" from categories to this table, and from brands to this table,
    But when i want to use features like RelationId i get the value of bt_brand_to_category_id
    Agusti Fernandez
    @agustif
    @alexeightsix Hey Alexander, yes that's indeed possible. You can see a good example on https://github.com/w3tecch/express-typescript-boilerplate/ of both, using faker under the hood for factories
    This repo boilerplate was what made me stick with TS/TypeORM. Hope it helps . They ended up creating a npm package for typeorm seeding: https://github.com/w3tecch/typeorm-seeding
    CoonHouse
    @CoonHouse
    Hello, how do I use the .collation() cursor on repository.createEntityCursor() on MongoDB?
    Saulo S. Toledo
    @saulotoledo
    Hello all. I am having issue with a sample project here. Can somebody help me to find the issuew
    /* tslint:disable:completed-docs no-any */
    import { MigrationInterface, QueryRunner } from 'typeorm';
    
    import { User } from '../../modules/core/entities/user.model';
    
    export class AddSampleUsers1557597276952 implements MigrationInterface {
    
      public async up(queryRunner: QueryRunner): Promise<any> {
        await queryRunner
          .manager
          .createQueryBuilder()
          .insert()
          .into(User)
          .values([
            { name: 'John Doe', email: 'john@doe.com', username: 'john.doe', password: '12345' },
            { name: 'Agata Doe', email: 'agata@doe.com', username: 'agata.doe', password: '12345' },
          ])
          .execute();
      }
    
      public async down(queryRunner: QueryRunner): Promise<any> {
        await queryRunner
          .manager
          .createQueryBuilder()
          .delete()
          .from(User)
          .where('email = :email', { email: 'john@doe.com' })
          .orWhere('email = :email', { email: 'agata@doe.com' })
          .execute();
      }
    
    }
    The error when I run the migration:
    Error during migration run:
    TypeError: this.subQuery is not a function
    node_modules/typeorm/query-builder/QueryBuilder.js:361:57
    Shijie Zhou
    @shijiezhou1
    using sql query instead of this query runner.
    Dominic Watson
    @intellix
    is it known that doing qb.addOrderBy('updatedAt', 'ASC') doesn't quote the column when the table name isn't prefixed like Asset.updatedAt in Postgres? Didn't see an issue for it. It causes an error like: No column updatedat because of it being unquoted
    Toni
    @SpeedoPasanen
    Using Webpack (nrwl/nx + angular cli) How to fix a circular dependency between entities which relate to each other?
    eg. page.entity.ts:
    @OneToMany(type => Pic, item => item.page)
    pic.entity.ts:
    @ManyToOne(type => Page, item => item.pics, { onDelete: 'CASCADE' })
    obviously these entities have to import each other to make that happen the usual way. Webpack says no-no. Any ideas?
    Toni
    @SpeedoPasanen
    meh hmn i guess i need to add interfaces, which entities implement
    Toni
    @SpeedoPasanen
    nope the related type needs to be an entity. What to do?
    Toni
    @SpeedoPasanen
    ok just use an interface on the ManyToOne end, lose the decorator there
    will lose the benefit of any cascaded saves but who uses them anyway... :)
    Agusti Fernandez
    @agustif
    Toni, check out this, you can use typeorm with graphql+modules 👌🏻 https://link.medium.com/oxU6b8Is8W
    Toni
    @SpeedoPasanen
    @agustif Really, moving to graphql is the only way? :) I like REST too much, will have to figure out a way to use an injector or something to get the entity classes for the decorators :)
    Toni
    @SpeedoPasanen
    ok only using @ManyToOne() is enough to create foreign keys etc. I thought you need to do @OneToMany() in the related entity as well. Guess I can live without it
    miran
    @drekembe
    hi, love typeorm! one question, is there still no way when adding a relation (either via createQueryBuilder().innerJoinAndSelect or find({ relations: [ ... ] })) to specify which fields you want returned on the relation?
    say i have a user, and i want to get that user, their posts, but the posts should contain only the titles
    ssdk86
    @ssdk86

    @ssdk86
    Hello, guys.
    in php doctrine ORM we have opportunity to set order by default in model instance like this
    @ORM\OrderBy({"date" = "DESC"})
    for example so we set order to addresses items as order : [[ 'date', 'DESC' ]]

        /**
        * @var \KR\Model\PeopleAddresses[]
        *
        * @ORM\OneToMany(targetEntity="\PeopleAddresses", mappedBy="people")
        * @ORM\OrderBy({"date" = "DESC"})
        * @ORM\JoinColumn(name="id", referencedColumnName="people_id")
        */
    protected $addresses;

    and is there a way to do that in typeorm?

        @Field(type => OrdersModel, { nullable : true })
    ***@OrderBy('date', 'DESC')***
        @HasMany(() => OrdersModel)
        ordersItem: OrdersModel;

    i try like this, but it is not work

        @Field(type => OrdersModel, { 
            nullable : true,
            defaultValue: [{
                key: "date",
                order: "ASC"
            }]
        })
        @HasMany(() => OrdersModel)
        ordersItem: OrdersModel;
    jmls
    @jmls
    hi all, is it possible to specify a field list for a relation in a find ?
    Lyth0
    @Lyth0
    Hey, entityManager.save does insert or update. Is there a good way to find out what the entityManager did?
    Thomas Reggi
    @reggi
    Hey All, i am looking for a way to get all relations for a specific entity. Could use some help.
    https://stackoverflow.com/questions/56888170/get-relations-for-a-specific-entity
    Lyth0
    @Lyth0

    @reggi I looked into the github code. Found something like:

    hasRelation<T>(target: ObjectType<T>|string, relation: string|string[]): boolean {
            const entityMetadata = this.connection.getMetadata(target);
            const relations = relation instanceof Array ? relation : [relation];
            return relations.every(relation => {
                return !!entityMetadata.findRelationWithPropertyPath(relation);
            });
        }

    may this help you? :o

    Thomas Reggi
    @reggi
    @Lyth0 I tried using this.connection.getMetadata, for some reason it was taking for ever to run
    Lyth0
    @Lyth0
    give me a second. I try to run it on my code
    I got the response instantly :o
    getConnection().getMetadata(Entity);
    Thomas Reggi
    @reggi
    hmmmm
    weird
    I'll look into this thanks @Lyth0
    carrow
    @carrowheap
    Hi everyone, I'm new to TypeORM, after npm run typeorm migration:run there isn't any table created in the database while I've an entity in my project. can someone help me to solve this problem.
    organisation_not_found.png
    organisation_entity.png
    Thomas Reggi
    @reggi
    @carrowheap I've never migrated manually, once you set up the entities and make a connection the tables are created automatically.
    Question: I am trying to query on deep relations, can this be done? https://stackoverflow.com/questions/56993963/query-by-deep-properties-on-relations
    Thomas Reggi
    @reggi
    Trying to do this the legitimate way using .createQueryBuilder() and it's not returning the correct data, but the raw SQL is. Any ideas what I'm missing?
    typeorm/typeorm#4423
    Mark Everett
    @TreeMan360
    hey, what is the instance scope for a subscriber? Is it a singleton or per-request?
    i.e can I safely store previous value as a member variable in beforeUpdate and then compare changes in afterInsert? Or will this suffer from concurrency issues?
    Aaron Rice
    @adrice727
    I'm running into a databaseColumn type for User#email is not defined and cannot be guessed error when starting my server. I've seen typeorm/typeorm#2897, but I don't understand how the babel plugin is supposed to fix the issue.
    carrow
    @carrowheap
    HI everyone, is there any way to clear content show by typeorm schema:log ?
    Thomas Reggi
    @reggi
    Thomas Sieverding
    @Bajix
    If you define a join table and have two one-to-many relationships with it, can you also have a many-to-many?
    Looking at the example there, couldnt that be taken a step further to define a many to many using the defined/extended table?
    Alessandro Tagliapietra
    @alex88
    Hi everyone, does having a composite primary key with a number and a many to one column work?

    I've tried with

    @ManyToOne(type => Invoice, invoice => invoice.lines, {
      primary: true
    })
    invoice: Invoice;
    
    @PrimaryColumn()
    @Column()
    orderLineNum: number;

    but it overwrites the primary key with the many to one primary key and then after the migration only one column is primary