Code

#20314 closed New feature (wontfix)

provide a management command to database views to cover inheritance

Reported by: chris@… Owned by: nobody
Component: Database layer (models, ORM) Version: 1.5
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

if you use inheritance like this:

class Foo(models.Model):
  a = models.CharField(max_length=10)

class Bar(Foo):
  b = models.CharField(max_length=10)

That will lead to two tables being created:

create table myapp_foo(id int, a varchar(10));
create table myapp_bar(foo_id, b varchar(10));

That's great. But when I need to run queries directly against the database, I have to write all the joins myself. Since I'm (extraordinarily) lazy, I would love to see a new management command that creates a view like this:

create view bar_view as -- i hate that name, but it's good for an example
select *                -- if I did this for real, I would enumerate the columns
from myapp_foo
join myapp_bar on myapp_foo.id = myapp_bar.foo_id

for this trivial example, the typing isn't that much. But when you get deep inheritance hierachies, the typing becomes a pain (especially since the name of the "id" key keeps changing at each level).

Attachments (0)

Change History (1)

comment:1 Changed 14 months ago by russellm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to wontfix
  • Status changed from new to closed

I can see what you're asking for here, and I can see the value, but Django doesn't currently have *any* support for views, so this seems a little premature.

In the meantime, you don't have to create the joins -- Django's ORM will create the joins for you.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.