Hello!
On Thu, Feb 22, 2007 at 08:47:46AM +0800, Peter Butler wrote:
> 1. When the script is run, neither the pw_product_forecast nor the
> pw_purchase_map tables are created. However, pw_forecast_resolution
> (the other related join) is created.
To allow SQLObject to create all tables you have to create RelatedJoins
in both direction. See the modified program and its output below. Do they
look right? I thjink all atbles are created now.
class Registration(SQLObject):
class sqlmeta:
table = 'pw_registration'
firstName = StringCol(length=50, default='peter')
lastName = StringCol(length=50)
email = StringCol(length=80)
password = StringCol(length=50, default=None)
purchases = MultipleJoin('Purchase')
class Purchase(SQLObject):
class sqlmeta:
table = 'pw_purchase'
purchaseDateTime = DateTimeCol()
modifiedDateTime = DateTimeCol()
registration = ForeignKey('Registration')
product = ForeignKey('Product')
maps = RelatedJoin('Map', intermediateTable='pw_purchase_map')
class Product(SQLObject):
class sqlmeta:
table = 'pw_product'
name = StringCol(length=80)
description = StringCol()
forecasts = RelatedJoin('Forecast', intermediateTable='pw_product_forecast')
class Forecast(SQLObject):
class sqlmeta:
table = 'pw_forecast'
name = StringCol(length=80)
description = StringCol()
products = RelatedJoin('Product', intermediateTable='pw_product_forecast')
resolutions = RelatedJoin('Resolution',
intermediateTable='pw_forecast_resolution')
class Resolution(SQLObject):
class sqlmeta:
table = 'pw_resolution'
name = StringCol(length=20)
resolution = IntCol()
forecasts = RelatedJoin('Forecast',
intermediateTable='pw_forecast_resolution')
class Map(SQLObject):
class sqlmeta:
table = 'pw_map'
name = StringCol(length=80)
parent = ForeignKey('Map')
areas = MultipleJoin('MapArea', joinColumn='map_id')
resolution = ForeignKey('Resolution')
purchases = RelatedJoin('Purchase', intermediateTable='pw_purchase_map')
class MapArea(SQLObject):
class sqlmeta:
table = 'pw_map_area'
name = StringCol(length=80)
x = IntCol()
y = IntCol()
width = IntCol()
height = IntCol()
linkedMap = ForeignKey('Map')
map = ForeignKey('Map')
CLASSES = [Registration, Product, Forecast, Resolution, Map, MapArea, Purchase]
def create():
for cl in CLASSES:
cl.createTable()
def drop():
for cl in CLASSES:
cl.dropTable(ifExists=True)
if __name__ == '__main__':
drop()
create()
1/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_registration'
1/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_registration'
2/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_product'
2/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_product'
3/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_forecast'
3/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_forecast'
4/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_resolution'
4/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_resolution'
5/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_map'
5/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_map'
6/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_map_area'
6/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_map_area'
7/QueryOne: SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_purchase'
7/QueryR : SELECT tbl_name FROM sqlite_master WHERE type='table' AND
tbl_name = 'pw_purchase'
8/Query : CREATE TABLE pw_registration (
id INTEGER PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(80),
password VARCHAR(50)
)
8/QueryR : CREATE TABLE pw_registration (
id INTEGER PRIMARY KEY,
first_name VARCHAR(50),
last_name VARCHAR(50),
email VARCHAR(80),
password VARCHAR(50)
)
9/Query : CREATE TABLE pw_product (
id INTEGER PRIMARY KEY,
name VARCHAR(80),
description TEXT
)
9/QueryR : CREATE TABLE pw_product (
id INTEGER PRIMARY KEY,
name VARCHAR(80),
description TEXT
)
10/Query : CREATE TABLE pw_forecast (
id INTEGER PRIMARY KEY,
name VARCHAR(80),
description TEXT
)
10/QueryR : CREATE TABLE pw_forecast (
id INTEGER PRIMARY KEY,
name VARCHAR(80),
description TEXT
)
11/Query : CREATE TABLE pw_product_forecast (
pw_forecast_id INT NOT NULL,
pw_product_id INT NOT NULL
)
11/QueryR : CREATE TABLE pw_product_forecast (
pw_forecast_id INT NOT NULL,
pw_product_id INT NOT NULL
)
12/Query : CREATE TABLE pw_forecast_resolution (
pw_forecast_id INT NOT NULL,
pw_resolution_id INT NOT NULL
)
12/QueryR : CREATE TABLE pw_forecast_resolution (
pw_forecast_id INT NOT NULL,
pw_resolution_id INT NOT NULL
)
13/Query : CREATE TABLE pw_resolution (
id INTEGER PRIMARY KEY,
name VARCHAR(20),
resolution INT
)
13/QueryR : CREATE TABLE pw_resolution (
id INTEGER PRIMARY KEY,
name VARCHAR(20),
resolution INT
)
14/Query : CREATE TABLE pw_map (
id INTEGER PRIMARY KEY,
name VARCHAR(80),
parent_id INT CONSTRAINT parent_id_exists REFERENCES pw_map(id) ,
resolution_id INT CONSTRAINT resolution_id_exists REFERENCES
pw_resolution(id)
)
14/QueryR : CREATE TABLE pw_map (
id INTEGER PRIMARY KEY,
name VARCHAR(80),
parent_id INT CONSTRAINT parent_id_exists REFERENCES pw_map(id) ,
resolution_id INT CONSTRAINT resolution_id_exists REFERENCES
pw_resolution(id)
)
15/Query : CREATE TABLE pw_purchase_map (
pw_map_id INT NOT NULL,
pw_purchase_id INT NOT NULL
)
15/QueryR : CREATE TABLE pw_purchase_map (
pw_map_id INT NOT NULL,
pw_purchase_id INT NOT NULL
)
16/Query : CREATE TABLE pw_map_area (
id INTEGER PRIMARY KEY,
name VARCHAR(80),
x INT,
y INT,
width INT,
height INT,
linked_map_id INT CONSTRAINT linked_map_id_exists REFERENCES pw_map(id) ,
map_id INT CONSTRAINT map_id_exists REFERENCES pw_map(id)
)
16/QueryR : CREATE TABLE pw_map_area (
id INTEGER PRIMARY KEY,
name VARCHAR(80),
x INT,
y INT,
width INT,
height INT,
linked_map_id INT CONSTRAINT linked_map_id_exists REFERENCES pw_map(id) ,
map_id INT CONSTRAINT map_id_exists REFERENCES pw_map(id)
)
17/Query : CREATE TABLE pw_purchase (
id INTEGER PRIMARY KEY,
purchase_date_time TIMESTAMP,
modified_date_time TIMESTAMP,
registration_id INT CONSTRAINT registration_id_exists REFERENCES
pw_registration(id) ,
product_id INT CONSTRAINT product_id_exists REFERENCES pw_product(id)
)
17/QueryR : CREATE TABLE pw_purchase (
id INTEGER PRIMARY KEY,
purchase_date_time TIMESTAMP,
modified_date_time TIMESTAMP,
registration_id INT CONSTRAINT registration_id_exists REFERENCES
pw_registration(id) ,
product_id INT CONSTRAINT product_id_exists REFERENCES pw_product(id)
)
Oleg.
--
Oleg Broytmann http://phd.pp.ru/ [EMAIL PROTECTED]
Programmers don't die, they just GOSUB without RETURN.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss