Comments (9)
Lucid seems to require the field deleted_at
. I had the same issue and fixed it by adding the field deleted_at
manually.
To define a model you simply need to create a es2015 class and extend from Lucid
.
// Models/UserModel.js
'use strict';
const Lucid = use("Lucid");
class User extends Lucid { }
module.exports = User;
from core.
When you say you manually added the delete_at field, are you talking about inside your User model class javascript file or are you talking about directly in the SQL file ?
What you've shown there is defining a User model but how does one specify the properties of that User model ?
At the moment, the User model is blank, it hasn't specified that a User model should have a username, or password, or email, or age, or gender, etc.
I have tried:
'use strict'
const Lucid = use("Lucid")
class User extends Lucid {
constructor() {
this.username = '';
this.password = '';
}
}
module.exports = User
Like how is demonstrated here: https://babeljs.io/docs/learn-es2015/
but I get a console error:
this is not defined
.
I sincerely hope we don't leave a User model empty and somehow have to open the SQL file to see what properties a model has...that would be terribad. :D
from core.
@chewedon there seems to be confusion, let me address them.
- Adonis orm has a concept of
soft deletes
which means whenever you delete a row it is not deleted in database, infact a field calleddeleted_at
is updated to mark the row as deleted. You can turn it off by inside your model.
http://adonisjs.com/docs/2.0/lucid#soft-deletes - Lucid is only a sql orm and follows active record pattern, so there is no need to define schema inside your models as they only makes model dirty and harder to read. In order to setup database you can use migrations using
ace
commands.
from core.
@thetutlage hello, thanks for replying :D
- Yes, I've read briefly about the soft delete but problem is, I am not even deleting, all I'm doing is fetching.
As you can see from my example code I've shown above, all I did was generate a new Adonis project, created a few User model and then tried to do a fetch all Users using the User.all()
method but that itself caused a crash and said delete_at
field is missing which it is when looking at the generated SQLite table itself.
I am not even doing any delete
operation in my code. I was expecting User.all()
to give me the same result as Database.table('user').select('*')
.
If Lucid requires that delete_at
field, and soft delete is on by default, how come the database migration didn't generate the field delete_at
when user run the ace command to migrate database ?
- So let's say a new project has been underway by one man. Then months later, a new developer come on board the team, in order for the new developer to know what properties an entity such as
User
has, he needs to open the SQLite file and look at all the columns OR go through every migration file and see what operation was done on the table schema, i.e. new column inserted, deleted, updated etc
If this new developer does not have access to the SQL database file because he's working remotely, if becomes an even bigger problem.
I don't see how schema inside a model class makes it dirty and harder to read than any other regular Object Oriented Programming Class.
You're already going to have code like:
class User extends Lucid {
posts () {
return this.hasMany('App/Model/Post')
}
}
Now the programmer needs to look at the User
class to see what relationship it has, as well as the SQL file, i.e. two separate places to visit to get the information he needs.
Do you see that as a problem ?
Maybe I just need to get used to it :D
from core.
Okay, first when you are fetching rows, it is ORM responsibility to make sure you are not getting deleted rows (soft deleted rows), so the fetch query will have to add a where clause.
Next having schema inside the model is a pain not a relief, may be from smaller point it seems nice but it take the flexibility of versioning a database.
Here are some nice articles which simply talks about why versioning of database is required. http://enterprisecraftsmanship.com/2015/08/10/database-versioning-best-practices.
http://flywaydb.org/getstarted/why.html
It is all about design practices which are followed by Adonis, and every design practice comes with goods and bads.
Finally, why migration file does not creates a deleted_at
column, this is something needs improvement and i will fix it. From going onwards, every new migration file will have timestamps
and deleted_at
columns by default.
from core.
I see. I'll venture on and see how well Adonis synergizes with me :D
So far, I was able to do a simple image upload, place the image file inside the public folder and it was served immediately on my views, so it is a good start, liking it so far.
from core.
Great 👍
from core.
Create issue on lucid
repo adonisjs/lucid#12
from core.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from core.
Related Issues (20)
- Hashing HOT 5
- Feature - Vine and request HOT 5
- Broken Installation of the Slim Starter Kit. HOT 6
- Bun support for ace add
- Install version 5 of Adonis in node 18 e 20 HOT 1
- Startup project error - mysql version
- The requested module 'node:module' does not provide an export named 'register' Error HOT 1
- Error: "Top-level await is not available in the configured target environment" HOT 1
- Undefined `@adonisjs/lucid/services/db` in commands HOT 2
- JAPA does not make correct API calls, unpredictably HOT 5
- Build Error HOT 5
- Env with special characters HOT 2
- ReferenceError: DateTime is not defined HOT 1
- Creating tests for commands cause "Error: ERR_PACKAGE_IMPORT_NOT_DEFINED #commands/greet" HOT 1
- Health checks cannot be performed as commands HOT 1
- Event object passed as object within object HOT 2
- Failed to load url inertia/app/ssr.tsx (resolved id: inertia/app/ssr.tsx). Does the file exist? HOT 2
- .env files for different node environments are not working HOT 2
- transmit.authorizeChannel not called HOT 1
- Do not use TypeScript features that require transformation (features that doesn't exist in JavaScript) like experimentalDecorators HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from core.