Answer the question
In order to leave comments, you need to log in
Why did they come up with models in django/laravel if there are sql queries?
After all, in order to use them, you need to re-learn a whole separate technology.
Answer the question
In order to leave comments, you need to log in
ORM is the highest level of abstraction when working with a database.
It allows using simpler structures to make queries to the database. At what to any DB from supported.
An example of "simpler" constructs (django):
Child.objects.filter(name__in=['Паша', 'Илья'], age__gte=18, parent__name='Игорь')
SELECT * FROM "main_child" INNER JOIN "main_parent" ON ("main_child"."parent_id" = "main_parent"."id") WHERE ("main_child"."age" >= 18 AND "main_child"."name" IN (Паша, Илья) AND "main_parent"."name" = Игорь)
from django.db import models
class Parent(models.Model):
name = models.CharField(max_length=50)
class Child(models.Model):
name = models.CharField(max_length=150)
age = models.IntegerField(default=0)
parent = models.ForeignKey(Parent, on_delete=models.CASCADE)
What you call models is actually called ORM/ODM.
And they were invented to reduce the cost of a separate database developer (sql developer) and give ordinary backenders a chance to write code without thinking about database queries. Well, the second side (also follows from the first) for greater flexibility / portability of the code. Those. if at some point in the development of the project you decided for some reason to change the database (which naturally has a different syntax), you did not have to rewrite everything again. Orm/odm will do everything for you.
And how do models "replace" SQL queries? This is what the SQL builder does, not the models.
After all, in order to use them, you need to re-learn a whole separate technology.
re-learn a whole separate technology
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question