hello guys
I am facing a tough day due to FindConditions/FindManyOptions in Repository.find method.
most of the worst, I've got this error :
[Nest] 26433 - 2019-09-06 12:37:02 [ExceptionsHandler] Maximum call stack size exceeded +3373ms
RangeError: Maximum call stack size exceeded
at String.split (<anonymous>)
at Function.QueryBuilderUtils.isAliasProperty (/home/fethijemli/Documents/dev/node/nest/CIO-FORUM-BACKEND/src/query-builder/QueryBuilderUtils.ts:17:15)
at JoinAttribute.getValue (/home/fethijemli/Documents/dev/node/nest/CIO-FORUM-BACKEND/src/query-builder/JoinAttribute.ts:143:40)
at JoinAttribute.get [as relation] (/home/fethijemli/Documents/dev/node/nest/CIO-FORUM-BACKEND/src/query-builder/JoinAttribute.ts:162:53)
at JoinAttribute.get [as metadata] (/home/fethijemli/Documents/dev/node/nest/CIO-FORUM-BACKEND/src/query-builder/JoinAttribute.ts:175:18)
at SelectQueryBuilder.join (/home/fethijemli/Documents/dev/node/nest/CIO-FORUM-BACKEND/src/query-builder/SelectQueryBuilder.ts:1299:27)
at SelectQueryBuilder.leftJoin (/home/fethijemli/Documents/dev/node/nest/CIO-FORUM-BACKEND/src/query-builder/SelectQueryBuilder.ts:284:14)
at SelectQueryBuilder.leftJoinAndSelect (/home/fethijemli/Documents/dev/node/nest/CIO-FORUM-BACKEND/src/query-builder/SelectQueryBuilder.ts:364:14)
at /home/fethijemli/Documents/dev/node/nest/CIO-FORUM-BACKEND/src/find-options/FindOptionsUtils.ts:246:16
at Array.forEach (<anonymous>)
Hi! I'm facing an issue with typeorm that I'm having trouble solving:
I have a entity
@Entity('my_entity_table')
class MyEntity implements MyEntityInterface {
@PrimaryColumn({ type: 'int' })
public id: number;
@Column({ type: 'varchar' })
@MaxLength(1000)
public message: string;
}
now when I do a queryBuilder and a getMany()
, I would like to have this new field in the result which is aggregated from other database tables
e.g.
// query builder for myEntity
myQueryBuilder
.addSelect(`EXISTS (
SELECT true
FROM other_table`, 'myAggregateField'
)
.getMany()
how can I include the myAggregateField in the result?
public myAggregateField?: boolean;
to the MyEntity-class, but it didnt help
I'm getting an error in a browser app bundled using web pack with sql.js@1.1.0
:
TypeError: Cannot read property 'Database' of undefined
at SqljsDriver.eval (webpack:///./node_modules/typeorm/browser/driver/sqljs/SqljsDriver.js?:278:62)
at step (webpack:///./node_modules/tslib/tslib.es6.js?:120:23)
at Object.eval [as next] (webpack:///./node_modules/tslib/tslib.es6.js?:101:53)
at eval (webpack:///./node_modules/tslib/tslib.es6.js?:94:71)
at new Promise (<anonymous>)
at Module.__awaiter (webpack:///./node_modules/tslib/tslib.es6.js?:90:12)
at SqljsDriver.createDatabaseConnectionWithImport (webpack:///./node_modules/typeorm/browser/driver/sqljs/SqljsDriver.js?:272:63)
at SqljsDriver.eval (webpack:///./node_modules/typeorm/browser/driver/sqljs/SqljsDriver.js?:137:56)
at step (webpack:///./node_modules/tslib/tslib.es6.js?:120:23)
at Object.eval [as next] (webpack:///./node_modules/tslib/tslib.es6.js?:101:53)
it looks like it's inside SqljsDriver.prototype.createDatabaseConnectionWithImport = function (database)
at line isLegacyVersion = typeof this.sqlite.Database === "function";
, downgrading to sql.js@0.5.0
solves that
Hey guys, I'm having a bit of problem with ManyToMany relationship
My entities are:
@Entity()
export class Product {
@PrimaryColumn('text')
sku: string;
@Column('text')
name: string;
@Column({ name: 'cost_price', type: 'real' })
costPrice: number;
@Column({ name: 'sell_price', type: 'real' })
sellPrice: number;
@Column('datetime', { name: 'creation_date' })
creationDate: Date;
@Column('datetime', { name: 'mod_date' })
modificationDate: Date
@ManyToMany(type => Category)
@JoinTable({name: 'product-categories'})
categories: Category[];
static create = (props: Product) => {
let product = new Product()
product.sku = props.sku
product.name = props.name
product.costPrice = props.costPrice
product.sellPrice = props.sellPrice
product.creationDate = props.modificationDate
product.modificationDate = props.modificationDate
product.categories = props.categories
return product
}
}
@Entity()
export class Category {
@PrimaryGeneratedColumn('rowid')
id: string;
@Column("text")
name: string;
@Column('datetime', { name: 'creation_date' })
creationDate: Date;
static create = (props: { name: string, creationDate: Date }) => {
let category = new Category()
category.name = props.name
category.creationDate = props.creationDate
return category
}
}
I'm creating new rows using this bit of code:
let beverageCategory = Category.create({
creationDate: new Date(),
name: 'Beverage'
})
await categoryDb.save(beverageCategory)
let pepsi = Product.create({
sku: '10000001',
categories: [beverageCategory],
costPrice: 2.49,
sellPrice: 2.94,
creationDate: new Date(),
modificationDate: new Date(),
name: 'Pepsi 2L'
})
await productDb.save(pepsi)
But nothing shows up in the product-categories
table
synchronize=false
in it?
ManyToMany
relation with Category
, needed the category objects to have a valid id. And since I was creating the Category objects to add to Product didn't have reference to db generated keys, it couldn't recognize it. If I draw the same object from database before passing onto Products, it works like magic.