Giter VIP home page Giter VIP logo

Comments (9)

gearsdigital avatar gearsdigital commented on August 25, 2024

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.

chewedon avatar chewedon commented on August 25, 2024

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.

thetutlage avatar thetutlage commented on August 25, 2024

@chewedon there seems to be confusion, let me address them.

  1. Adonis orm has a concept of soft deletes which means whenever you delete a row it is not deleted in database, infact a field called deleted_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
  2. 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.

chewedon avatar chewedon commented on August 25, 2024

@thetutlage hello, thanks for replying :D

  1. 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 ?

  1. 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.

thetutlage avatar thetutlage commented on August 25, 2024

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.

chewedon avatar chewedon commented on August 25, 2024

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.

thetutlage avatar thetutlage commented on August 25, 2024

Great 👍

from core.

thetutlage avatar thetutlage commented on August 25, 2024

Create issue on lucid repo adonisjs/lucid#12

from core.

lock avatar lock commented on August 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.