AdonisJS Tutorial - Setup and Query Many to Many Relationships with Lucid

preview_player
Показать описание
In this video I show you how to use Lucid to set up and query many to many relationships in a MySQL database.

AdonisJS is an MVC framework for NodeJS.

Github Repos:

**Related YouTube Videos**

Load Related Data with Eager Loading -

Рекомендации по теме
Комментарии
Автор

Many years after with some changes this video is still useful. Thank You very much

michelmbili
Автор

Love your videos and the fact that Master Virk has taken interest in you makes this a rock solid channel :)

peterdigitalit
Автор

Gentle feedback.

Instead of `detach` and `attach`, we can make use of the `sync` method. Which does the same thing.

Instead of saying
```
project.tags = await project.tags().fetch()
```

We can say
```
await project.load('tags')
```

amanvirk
Автор

the following error occurred while inserting the project: "insert into" project_tag "(" project_id ", " tag_id ") values ​​($ 1, $ 2) returning" id "- column" id "does not exist". How to solve?

wilsonmatokanovicjunior
Автор

Btw, do we really need to use `... onDelete('cascade')' ?

In docs said:
"The delete method removes the related row from the database. In case of belongsToMany, this method also drops the relationship from pivotTable"

vlad
Автор

How did you reformat your indent of dot/chain in vsc, any shortcuts? Thx

anonimusprogramustea
Автор

Hi, Patrick

Maybe you know, if there any difference between
```
table.string('slug')
table.index('slug')
```
and
```
table.string('slug').index()
```
Can't find answer in Google, and Knex docs doesn't make it clear...

vlad
Автор

Thanks for these videos! I am just beginning to check out Adonis and this channel is a huge discovery! Great work! One thing I am confused about with Adonis is the relationships. Do you have to define those relationships at the schema level as well as the model level, or does the model suffice? It seems like there are examples of both in the completed repo

johnmcguin
Автор

is possible to create a column or table without migration?

mufid
Автор

Awesome!
Didn’t know that we can do indexing in migration files

vlad
Автор

Thank you for your amazing videos! Do you know if Lucid has any method for update hasMany associations? For instance, I have an endpoint to update a customer order and I'd like to use saveMany on order.items() and remove itens if user remove some in frontend and update old itens and insert new ones.

amanciojr
Автор

Hi, your tutorial is very very easy to understand, thanks to upload it here! I have a question, if I have a many for many relationship that needs some additional data, like sales and product (sales have many products, and products have many sales), and each product have it own weight, how can I get this from the request, and save it in the pivot table? Thanks again for the tutorial!

ItaloCDC
Автор

Thank you for making these videos. Very much appreciated. The Adonis framework is pretty awesome, but some things are hard to understand. Good to see actual step-by-step examples.

Any plans to do a video on a Vue front-end and Adonis back-end, with authentication such as Auth0 or JWT? I've been trying to figure out a good approach to this or find example code.

Nondestructivetech
Автор

Hey man, nice tutorial. I'm facing an issue in my project, there is this table that has a many to many relationship with 3 other tables. The relationship with the first table worked, but it doesn't allow me to use the same column name in the other tables. And I'm having issues attaching to the pivot table.

For example, I have a User with a many to many relationship with Client and Agent => A user can have many clients and vice versa. so my pivot table for client_user looks like =>
this.create("client_user", table => {
table.increments();
table
.integer("client_id")
.unsigned()
.index("client_id");
table
.integer("user_id")
.unsigned()
.index("user_id");
table
.foreign("client_id")
.references("clients.id")
.onDelete("cascade");
table
.foreign("user_id")
.references("users.id")
.onDelete("cascade");
table.timestamps();
});


but I'm not allowed to use user_id as a column in the pivot table for agent_user =>
this.create("agent_user", table => {
table.increments();
table
.integer("agent_id")
.unsigned()
.index("agent_id");
table
.integer("user_id")
.unsigned()
.index("user_id");
table
.foreign("agent_id")
.references("agents.id")
.onDelete("cascade");
table
.foreign("user_id")
.references("users.id")
.onDelete("cascade");
table.timestamps();
});


migration doesn't run, with the error user_id already exist.

lanreadedara
join shbcf.ru