Hello,

I'm new to sqlalchemy and wondered how could I do this :

I have 2 tables (postgresql) :

create table invasive_categories (
  id          serial          not null,
  category    varchar(100)    not null,

  constraint pk_category
      primary key(id)
);

create table invasives (
  id                      serial          not null,
  original_name           varchar(200)    not null,
added timestamp not null default current_timestamp,
  category                integer     not null,

  constraint pk_invasive
      primary key (id),

  constraint fk_category
      foreign key (category) references invasive_categories(id)
);

I've done this :

from sqlalchemy import *

class Invasive(object): pass
class InvasiveCategory(object): pass

db_engine = create_engine('postgres://database=blabla&host=blabla.com&user=foo&password=bar', encoding='utf-8')

invasives = Table('invasives', db_engine, autoload = True)
invasive_categories = Table('invasive_categories', db_engine, autoload=True)

Invasive.mapper = mapper(Invasive, invasives)
InvasiveCategory.mapper = mapper(InvasiveCategory, invasive_categories)

cascade_mappers(Invasive.mapper, InvasiveCategory.mapper) // Invasive contains invasivecategory and InvasiveCategory contains invasives

It works, but how could I select all "Invasive" order by InvasiveCategory.category ?
I tried things like:

Invasive.mapper.select_by(order_by=[invasivecategory.category])
Invasive.mapper.select(order_by=[InvasiveCategory.c.category]) // This query doesn't fail, but a JOIN is missing ... (why ?)
...

Another question, why can't I select only some fields in a select_text() ? For example : Invasive.mapper.select_text('SELECT a.* FROM invasives a, invasive_categories b WHERE a.category=b.id') works but Invasive.mapper.select_text('SELECT a.original_name FROM invasives a, invasive_categories b WHERE a.category=b.id') fails ...

In advance, thanks for you answers


-------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to