Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: this.model.getRepository is not a function #15

Open
johannbuscail opened this issue Feb 26, 2021 · 4 comments
Open

TypeError: this.model.getRepository is not a function #15

johannbuscail opened this issue Feb 26, 2021 · 4 comments

Comments

@johannbuscail
Copy link

johannbuscail commented Feb 26, 2021

Hello,
I've been using AdminBro with Sequelize for a while now but I wanted to try it with TypeORM.
I've followed the doc step by step, but I get this error:

TypeError: this.model.getRepository is not a function
at Resource.prepareProps (C:\nodejs\test\ORM\typeorm\node_modules@admin-bro\typeorm\src\Resource.ts:120:36)
at new Resource (C:\nodejs\test\ORM\typeorm\node_modules@admin-bro\typeorm\src\Resource.ts:21:29)
at Database.resources (C:\nodejs\test\ORM\typeorm\node_modules@admin-bro\typeorm\src\Database.ts:15:22)

Here is my code:

import "reflect-metadata";

import express from "express";
import { Connection, createConnection } from "typeorm";

import AdminBro from "admin-bro";
import AdminBroExpress from "@admin-bro/express";
import * as AdminBroTypeORM from "@admin-bro/typeorm";

const app = express();
const PORT = process.env.PORT || 8080;

const main = async (connection: Connection) => {
        // init admin bro
	AdminBro.registerAdapter(AdminBroTypeORM);
	const adminBro = new AdminBro({
		databases: [connection],
		rootPath: "/admin",
	});
	const router = AdminBroExpress.buildRouter(adminBro);

        // start express server
	app.use(adminBro.options.rootPath, router);
	app.listen(PORT, () => console.log("Listening on", PORT));
};

createConnection()
	.then(main)
	.catch((error) => console.log(error));

Thanks in advance

@vensauro
Copy link

I too have this error, this is because the Model class use the datamapper aproach and not the active record.
The method https://github.com/SoftwareBrothers/admin-bro-typeorm/blob/7ff78547db5eb0c8344692c92577a973593437d7/src/Resource.ts#L25 this.model.getRepository() needs the model to extends the BaseEntity from typeorm

@derksacklowski
Copy link

I have the same problem. The base implementation without any resources fails with the mentioned issue

@derksacklowski
Copy link

Is there support for the datamapper approach planned?

@TPXP
Copy link

TPXP commented Aug 16, 2021

I'm having the same issue and worked on a patch circumventing the issue, you can get it here (apply with patch-package): https://gist.github.com/TPXP/ac29ad0fbf126b8470858ede6d8b6cdb

I haven't tested it against Data Mapper entities, so take extra care if your project mixes both types of entities.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants