SoftwareBrothers / adminjs

AdminJS is an admin panel for apps written in node.js
https://adminjs.co
MIT License
8.25k stars 665 forks source link

Many-to-many support #843

Closed sdepold closed 2 years ago

sdepold commented 3 years ago

First of all,

let me congratulate you for an amazing piece of software. It's extremely useful and well designed :)

Describe the problem feature solves Using Sequelize, I'm defining a many-to-many relationship like this:

Tag.belongsToMany(Wishlist, { through: TagWishlistReference });

So this thing is building the bridge between a Tag and a Wishlist.

Heading to the Create screen for TagWishlistReference, I only get an empty form that contains only a Save button.

Describe the solution you'd like I'd like to get 2 ID selectors, one for Tag and one for Wishlist just as it would be for manyToOne associations:

image

Describe alternatives you've considered I tried to integrate with https://gist.github.com/leibowitz/b94fc4eb2b8ab745267db99941757190 but couldn't get it to work.

Acceptance criteria

cett01 commented 3 years ago

any solutions or improvements?

sdepold commented 3 years ago

@dziraf Any chance to get a fix for this?

dziraf commented 2 years ago

This isn't really a bug, you need

TagWishlistReference.belongsTo(Tag);
TagWishlistReference.belongsTo(Wishlist);

for it to work

franka107 commented 1 year ago

I implemented an example, it is tested with typeorm and postgresql, You can test this project quickly with VSC dev containers, the example is in the many-to-many relationship User <-> Role, to enter the admin is localhost:3000/admin

https://github.com/franka107/nestjs-adminjs-manytomany-example

Screenshot from 2022-12-14 11-49-27 Screenshot from 2022-12-14 11-49-56 Screenshot from 2022-12-14 11-50-06

AshotN commented 1 year ago

@franka107 Is this something you plan on getting into the core of AdminJS?

damian-balas commented 1 year ago

@franka107 Awesome work! Thanks :)

image

Inoir commented 1 year ago

is this the recommendet way of implementing an many to many? @dziraf if so it may be worth taking the solution of @franka107 into the core of adminjs or provide some example of how to do this in "better" way. currently many to many is not working out of the box or needs some special handling i cant figure out. it seems the implementation is adoptable to some generic many to many implementation

ysavinkov commented 1 year ago

I implemented an example, it is tested with typeorm and postgresql, You can test this project quickly with VSC dev containers, the example is in the many-to-many relationship User <-> Role, to enter the admin is localhost:3000/admin

https://github.com/franka107/nestjs-adminjs-manytomany-example

Screenshot from 2022-12-14 11-49-27 Screenshot from 2022-12-14 11-49-56 Screenshot from 2022-12-14 11-50-06

can this be made using express + sequelize, or I have to rewrite the project with nest.js?

lpbonomi commented 9 months ago

There is now an official way to do this:

https://docs.adminjs.co/basics/features/relations