Thursday 23 January 2020

ObjectionJS

Hey guys,I have this class:class Item extends Model { user!: User; asset!: Asset; shares!: number; static tableName = 'items'; static idColumn = 'id'; static relationMappings = () => ({ user: { relation: Model.BelongsToOneRelation, modelClass: User, join: { from: 'items.userId', to: 'users.id' } }, asset: { relation: Model.HasManyRelation, modelClass: Asset, join: { from: 'items.assetId', to: 'assets.id' } } }); } and I wanna create a new Item. I want to check if the user and the asset exists. I tried to retrieve the user and the asset from the database before and do:await Item.query().insert({user, asset, shares: 0})but the ids in the table are still null then. I dont understand what the issue is here. Anyone got advice for me?Basically I would like to do something like:INSERT INTO case (scenario_id, employee_id) SELECT s.id, e.id FROM scenario AS s CROSS JOIN emplopyee AS e WHERE s.`key` = 'UC01' AND e.employee_no = '0001'

Submitted January 23, 2020 at 06:27PM by roconf

No comments:

Post a Comment