Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 1 and Version 2 of ViewsInSqlObject


Ignore:
Timestamp:
03/05/06 23:36:59 (13 years ago)
Author:
godoy
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ViewsInSqlObject

    v1 v2  
    3838 
    3939}}} 
     40 
     41------ 
     42 
     43This example also doesn't cover the case where you don't have an ID or you'd have to fake one.  The best solution I've found is concatenating IDs from tables involved and then using this result as the id for the view. 
     44 
     45{{{ 
     46class MyView(SQLObject): 
     47    class sqlmeta: 
     48        idType = 'str' 
     49        idName = 'concatenated_ids' 
     50 
     51    name_one = StringCol() 
     52    name_two = StringCol() 
     53    somebool = BoolCol() 
     54}}} 
     55 
     56For !PostgreSQL, creating this should be something like: 
     57 
     58{{{ 
     59CREATE VIEW myView AS SELECT table1.id::text || '.'::text || table2.id::text || '.'::text || table3.id::text as id, table1.col1, table2.col2, table3.col3 FROM table1, table2, table3 WHERE table1.something  = table2.otherthing AND table1.anotherthing = table3.yetanotherthing; 
     60}}} 
     61 
     62Since all tables have an id column that is unique, we grant that the resulting concatenation will also be unique and be the best choice for a complex view. 
     63 
     64''- Jorge Godoy''