createConnection TypeError: Cannot read property 'type' of undefined
See original GitHub issueIssue type:
[x ] question [ ] bug report [ ] feature request [ ] documentation issue
Database system/driver:
[ ] cordova
[x ] mongodb
[ ] mssql
[ ] mysql
/ mariadb
[ ] oracle
[ ] postgres
[ ] cockroachdb
[ ] sqlite
[ ] sqljs
[ ] react-native
[ ] expo
TypeORM version:
[x ] latest
[ ] @next
[ ] 0.x.x
(or put your version here)
Steps to reproduce or a small repository showing the problem:
export class Media {
@ObjectIdColumn()
public id: ObjectID;
@Column()
public instagramId: string;
@Column({ enum: ['image', 'video']})
public type: 'image' | 'video';
@OneToOne(type => InstaLink, link => link.media)
public link: InstaLink;
@Column()
public caption: string;
@Column()
public instagramCreatedTime: number;
@Column()
public images: {
thumbnail?: IMediaImage;
lowResolution?: IMediaImage;
standardResolution?: IMediaImage;
};
@ManyToOne(type => User, user => user.media)
public user: User;
constructor(instagramMedia: InstagramMedia, user: User) {
this.type = instagramMedia.type;
this.instagramId = instagramMedia.id;
this.caption = instagramMedia.caption.text;
this.images = {
thumbnail: {
url: instagramMedia.images.thumbnail.url,
height: instagramMedia.images.thumbnail.height,
width: instagramMedia.images.thumbnail.width
},
lowResolution: {
url: instagramMedia.images.low_resolution.url,
height: instagramMedia.images.low_resolution.height,
width: instagramMedia.images.low_resolution.width
},
standardResolution: {
url: instagramMedia.images.standard_resolution.url,
height: instagramMedia.images.standard_resolution.height,
width: instagramMedia.images.standard_resolution.width
}
};
this.user = user;
this.instagramCreatedTime = parseInt(instagramMedia.created_time);
}
}
I have this entity and when I’m creating connection i get this error :
TypeError: Cannot read property 'type' of undefined
at new Media (/home/vrondelli/projects/tokilabs/livebio/service/src/models/media.ts:39:32)
at EntityMetadata.create (/home/vrondelli/projects/tokilabs/livebio/service/src/metadata/EntityMetadata.ts:499:19)
at EntityMetadataValidator.validate (/home/vrondelli/projects/tokilabs/livebio/service/src/metadata-builder/EntityMetadataValidator.ts:111:47)
at /home/vrondelli/projects/tokilabs/livebio/service/src/metadata-builder/EntityMetadataValidator.ts:44:56
at Array.forEach (<anonymous>)
at EntityMetadataValidator.validateMany (/home/vrondelli/projects/tokilabs/livebio/service/src/metadata-builder/EntityMetadataValidator.ts:44:25)
at Connection.buildMetadatas (/home/vrondelli/projects/tokilabs/livebio/service/src/connection/Connection.ts:505:33)
at Connection.<anonymous> (/home/vrondelli/projects/tokilabs/livebio/service/src/connection/Connection.ts:189:18)
at step (/home/vrondelli/projects/tokilabs/livebio/service/node_modules/typeorm/node_modules/tslib/tslib.js:133:27)
at Object.next (/home/vrondelli/projects/tokilabs/livebio/service/node_modules/typeorm/node_modules/tslib/tslib.js:114:57)
at fulfilled (/home/vrondelli/projects/tokilabs/livebio/service/node_modules/typeorm/node_modules/tslib/tslib.js:104:62)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:228:7)
at emitWarning (internal/process/promises.js:65:17)
at emitPendingUnhandledRejections (internal/process/promises.js:109:11)
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
node.js - TypeError: Cannot read property 'createConnection ...
I'm new to node, and I'm trying to create a zendesk app that connects to mysql when the user inputs a value. Here's...
Read more >TypeError: Cannot read properties of undefined ... - MongoDB
I have this code here: import { MongoClient } from "mongodb"; const createConnection = () => { // let current = null; const...
Read more >How to resolve a 'cannot read property connect of undefined ...
You get this error because the variable object is not defined, and trying to retrieve, set or mutate the property “id” on undefined...
Read more >Node JS TypeError: Cannot read property 'query' of undefined
I will provide a simple example of finding an error cannot read property 'query' of undefined. In this example use CRUD in the...
Read more >cannot read properties of undefined (reading 'query') - You.com
The app.use('/api/addReferFriend', addReferFriend); has to be after the app.use(async function(req, res, next) { .. let connection = mysql.createConnection( ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Well, I got your error it says you are trying to use
type
of undefined which probably throwing from thatthis.type = instagramMedia.type;
NOTE: Please do not post issues outside of typeorm’s scope.
Hey @vrondelli. From docs https://typeorm.io/#/entities.
So mark your constructor arguments as optional and handle undefined values.
Warning: This behavior is subject to change in next versions as it is discussed in https://github.com/typeorm/typeorm/issues/1772, https://github.com/typeorm/typeorm/pull/3845 and also https://github.com/typeorm/typeorm/pull/3910.