[sqlalchemy] Failures with AssociationProxy (starting with r2598)

2007-06-11 Thread Paul Kippes

Starting with r2598, I'm seeing some failures with how I'm using the
association proxy.  I've modified the
examples/association/proxied_association.py file which duplicates the
problem.

It is possible that I'm not suppose to remove associations like I am.
But it did work before (in 0.3.7 and 0.3.6).

It looks like if I read in part of the association into the current
session and then delete it, things don't go so well.

Index: examples/association/proxied_association.py
===
--- examples/association/proxied_association.py (revision 2723)
+++ examples/association/proxied_association.py (working copy)
@@ -106,8 +106,18 @@



+# new additions to proxied_association.py

+#engine.echo = True

+new_item = Item('new item', 100)
+session.clear()
+order = session.query(Order).get_by(customer_name='john smith')
+bogus = order.items[0].item_id  # comment out and it works on 0.3.8
+order.itemassociations = None
+session.flush()
+order.items.append(new_item)
+session.flush()



It fails with:
sqlalchemy.exceptions.SQLError: (IntegrityError) orderitems.order_id
may not be NULL u'INSERT INTO orderitems (item_id, price) VALUES (?,
?)' [5, 100]

Thanks,
Paul

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] assign_mapper patch

2007-06-11 Thread Simon Wittber

Hi, I've modified assign_mapper so that it won't monkey patch methods
which already exist on a mapped class.

Whether this is correct behaviour or not probably depends on ones
point of view... but I thought I'd submit the patch for consideration
anyway.

http://www.sqlalchemy.org/trac/attachment/ticket/596/assignmapper.diff

-Sw.


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: [MySQL] Checking if commit() is available

2007-06-11 Thread Michael Bayer


On Jun 11, 2007, at 6:46 PM, Monty Taylor wrote:

>
> Um - transactions have happily been there since 3.23.15. :)
>
> So the "best" way to do this is to check the db version and see if  
> it's
> greater than 3.23.15 or not.
>
> "show variables like 'version'" will do the trick to get you the
> version. If it's later than 3.23.15 you should be fine.
>

how about rollback() ?  we have a note that it fails if you arent  
using InnoDB tables.  of course this is something that should be  
addressed by MySQLDB.

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] PYTZ and SA

2007-06-11 Thread Michael Carter
Hello,

I was having some issues using pytz (python timezone definitions) with
sqlalchemy. Before I post the specifics of my problem, I'm curious if there
is any documentation on this kind of thing or If anyone else here had tried
it before.

Thanks,

Michael Carter

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: [MySQL] Checking if commit() is available

2007-06-11 Thread Monty Taylor

Michael Bayer wrote:
> 
> On Jun 8, 2007, at 2:17 PM, Andreas Jung wrote:
> 
>>
>> --On 8. Juni 2007 14:05:39 -0400 Rick Morrison  
>> <[EMAIL PROTECTED]> wrote:
>>
>>> try:
>>> t.commit()
>>> except:
>>> print 'Holy cow, this database is lame'
>>>
>>>
>> This code is also lame :-) The code should work
>> for arbitrary DSNs and swallowing an exception while
>> committing is evil, evil, evil.
> 
> with a pre-5 version of mysql, it is the lesser evil

Um - transactions have happily been there since 3.23.15. :)

So the "best" way to do this is to check the db version and see if it's
greater than 3.23.15 or not.

"show variables like 'version'" will do the trick to get you the
version. If it's later than 3.23.15 you should be fine.

Monty


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: multiple mappers on une table problem.

2007-06-11 Thread Michael Bayer


On Jun 11, 2007, at 12:21 PM, Glauco wrote:

> For this reason i've inserted explicit primaryjoin condition, and  
> these condition work perfectly in the primary mapper.
> But in the secondary wont work...
>

theres many reasons why you probably dont want to do what youre  
trying to do.

first off, adding relations to a non-primary mapper:  the class still  
will lazy load relationships from the primary mapper, since they are  
invoked from attributes.  it doesnt entirely make sense to add  
relationships to a secondary mapper for this reason - the  
relationships will only take effect from the secondary mapper if you  
are using eager loading.  and in that case, we dont really have any  
test cases for that so i cant say how well its going to work.

secondly: a non-primary mapper is just an awkward way of defining an  
ORM query.  Since we support generative queries now, you can just  
make a Query object with the criterion youre looking for and just  
hold onto it...youre just adding a single WHERE criterion, so  
my_secondary_query = query(MyClass).filter(table.c.tipo=='p').  much  
easier.   ideally Query should be replacing 90% of all non_primary  
mapper use cases.

thirdly:  it doesnt make much sense to use assign_mapper() with a  
secondary mapper, since thats not the mapper which the class is  
primarily associated with.

So after all that, if you still want to get it to work, you need the  
primaryjoin criterion to be against the mapped selectable:

myselect  = select[mytable]).alias('myselect')

mapper(MyClass, myselect, non_primary=True, properties={
 'stuff': relation(OtherClass,  
primaryjoin=myselect.c.id==othertable.c.myid)
})

you also may need to add the foreign_keys=[] parameter which  
will identfify which columns in the join conditions are "foreign", if  
SA cannot figure out what they are.

mapper(MyClass, myselect, non_primary=True, properties={
 'stuff': relation(OtherClass,  
primaryjoin=myselect.c.id==othertable.c.myid, foreign_keys= 
[othertable.c.myid])
})

hope this helps...good luck




--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SQLError.... label Error

2007-06-11 Thread Michael Bayer


On Jun 11, 2007, at 12:14 PM, Glauco wrote:

> my problem is exactly this...  i don't use aliases, and the example  
> is a qru constructed by SA.

you can only order by tables that you have added to the query  
explicitly or via join().  you cant order by columns that are added  
by eager loading.

i.e.

Operatore.join('somerelation').order_by(relatedtable.c.name).list()



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: multiple mappers on une table problem.

2007-06-11 Thread Glauco
Michael Bayer ha scritto:
> On Jun 11, 2007, at 11:12 AM, Glauco wrote:
>
>   
>> This cause a lot of inspiegable problem to property that are perfecly
>> functional in the primary
>> sqlalchemy.exceptions.ArgumentError: Can't determine relation  
>> direction
>> for relationship 'Blabla.comune_nascita (Comune)' - foreign key  
>> columns
>> are present in neither the parent nor the child's mapped tables
>>
>> 
>
> you need to explicitly specify conditions like primaryjoin,  
> foreign_keys, etc.
>
> http://www.sqlalchemy.org/docs/ 
> adv_datamapping.html#advdatamapping_properties_customjoin
>
>   

For this reason i've inserted explicit primaryjoin condition, and these 
condition work perfectly in the primary mapper.
But in the secondary wont work...


class Anagrafica:
  bla bla

# my primary mapper
assign_mapper(context,
  Anagrafica,
  tbl['anagrafica'],
  column_prefix = 'anagrafica_',
  extension = SelectResultsExt(),
  properties = {
'comune' : relation( Comune,
   primaryjoin = tbl['anagrafica'].c.id_comune == 
tbl['comune'].c.id ),
'nazione': relation( Nazione,
   primaryjoin = tbl['anagrafica'].c.cod_nazionalita == 
tbl['nazione'].c.codice ),?
'comune_nascita' : relation( Comune,
   primaryjoin = tbl['anagrafica'].c.id_comune_nascita 
== tbl['comune'].c.id),
'nazione_nascita' : relation(Nazione,
   primaryjoin = tbl['anagrafica'].c.cod_nazione_nascita 
== tbl['nazione'].c.codice ),
'professione': relation( Professione ),
'titolo_studio'  : relation( TitoloStudio ),
})


# my secondary mapper
class Person( Anagrafica ):
pass

assign_mapper(context,
  Person,
  select([tbl['anagrafica']], tbl['anagrafica'].c.tipo == 
'P').alias('person'),
  column_prefix = 'anagrafica_',
  extension = SelectResultsExt(),
  non_primary = True,
  properties = {
'comune' : relation( Comune,
   primaryjoin = tbl['anagrafica'].c.id_comune == 
tbl['comune'].c.id ),
'nazione': relation( Nazione,
   primaryjoin = tbl['anagrafica'].c.cod_nazionalita == 
tbl['nazione'].c.codice ),?
'comune_nascita' : relation( Comune,
   primaryjoin = tbl['anagrafica'].c.id_comune_nascita 
== tbl['comune'].c.id),
'nazione_nascita' : relation(Nazione,
   primaryjoin = tbl['anagrafica'].c.cod_nazione_nascita 
== tbl['nazione'].c.codice ),
'professione': relation( Professione ),
'titolo_studio'  : relation( TitoloStudio ),
})


In [8]: Anagrafica.search()
Out[8]: 


In [9]: Person.search()
ArgumentError: Can't determine relation direction for relationship 
'Person.comune_nascita (Comune)' - foreign key columns are present in 
neither the parent nor the child's mapped tables




Some ideas?

Thank you
Glauco

-- 
++
  Glauco Uri - Programmatore
glauco(at)allevatori.com 
   
  Sfera Carta Software(r)  [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
++



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SQLError.... label Error

2007-06-11 Thread Glauco
Michael Bayer ha scritto:
> On Jun 11, 2007, at 11:19 AM, Glauco wrote:
>
>   
>> I use hardly the column prefix, so my query are always aliased.
>> this obviously cause a lot of problem whith the order_by clause  
>> (that NOT use the same aliases)
>>
>> 
>
> the approach here depends on how this query is being constructed.  if  
> you are using your own alias objects, insert the columns as  
> referenced from the alias object itself into the order_by clause.
>
> alias = mytable.alias('foo')
> alias.select(order_by=[alias.c.bar])
>
>
>   
my problem is exactly this...  i don't use aliases, and the example is a 
qru constructed by SA.

*Operatore.select_by().order_by( Anagrafica.c.nome).list()*
SQLError: (ProgrammingError) invalid reference to FROM-clause entry for 
table "anagrafica"
HINT:  Perhaps you meant to reference the table alias "anon_f3fb".
 'SELECT operatore.data_inizio_attivita AS 
operatore_data_inizio_attivita, operatore.password AS 
operatore_password, operatore.logname AS operatore_logname, 
operatore.id_anagrafica AS operatore_id_anagrafica, 
anon_4877.ts_ultima_modifica AS anon_4877_ts_ultima_modifica, 
anon_4877.id AS anon_4877_id, anon_4877.id_anagrafica AS 
anon_4877_id_anagrafica, anon_4877.id_operatore AS 
anon_4877_id_operatore, anon_4877.data_inizio AS anon_4877_data_inizio, 
anon_4877.bdn_data_ultima_modifica AS 
anon_4877_bdn_data_ultima_modifica, anon_4877.bdn_id AS 
anon_4877_bdn_id, anon_4877.codice_struttura AS 
anon_4877_codice_struttura, anon_4877.id_azienda AS 
anon_4877_id_azienda, anon_4877.stato_record AS anon_4877_stato_record, 
anon_4877.bdn_specie AS anon_4877_bdn_specie, anon_4877.id_precedente AS 
anon_4877_id_precedente, anon_4877.bdn_flag_carne_latte AS 
anon_4877_bdn_flag_carne_latte, anon_4877.data_fine AS 
anon_4877_data_fine, operatore.id AS operatore_id, anon_a2d6.codice AS 
anon_a2d6_codice, anon_a2d6.descrizione AS anon_a2d6_descrizione, 
anon_a2d6.group_id AS anon_a2d6_group_id, operatore.data_fine_attivita 
AS operatore_data_fine_attivita, operatore.zoperoles AS 
operatore_zoperoles, anon_f3fb.cod_nazionalita AS 
anon_f3fb_cod_nazionalita, anon_f3fb.id AS anon_f3fb_id, 
anon_f3fb.id_comune AS anon_f3fb_id_comune, anon_f3fb.cod_professione AS 
anon_f3fb_cod_professione, anon_f3fb.dato_fiscale AS 
anon_f3fb_dato_fiscale, anon_f3fb.localita AS anon_f3fb_localita, 
anon_f3fb.telefono AS anon_f3fb_telefono, anon_f3fb.email AS 
anon_f3fb_email, anon_f3fb.nome AS anon_f3fb_nome, anon_f3fb.tipo AS 
anon_f3fb_tipo, anon_f3fb.cod_titolo_studio AS 
anon_f3fb_cod_titolo_studio, anon_f3fb.indirizzo AS anon_f3fb_indirizzo, 
anon_f3fb.id_precedente AS anon_f3fb_id_precedente, 
anon_f3fb.cod_nazione_nascita AS anon_f3fb_cod_nazione_nascita, 
anon_f3fb.id_comune_nascita AS anon_f3fb_id_comune_nascita, 
anon_f3fb.stato_record AS anon_f3fb_stato_record, anon_f3fb.id_operatore 
AS anon_f3fb_id_operatore, anon_f3fb.cap AS anon_f3fb_cap, 
anon_f3fb.ts_ultima_modifica AS anon_f3fb_ts_ultima_modifica, 
anon_f3fb.data_nascita AS anon_f3fb_data_nascita \nFROM operatore LEFT 
OUTER JOIN azienda_veterinario AS anon_28bf ON anon_28bf.id_veterinario 
= operatore.id LEFT OUTER JOIN unita_aziendale AS anon_4877 ON 
anon_4877.id = anon_28bf.id_unita_aziendale LEFT OUTER JOIN acl AS 
anon_e91a ON operatore.id = anon_e91a.id_operatore LEFT OUTER JOIN ruolo 
AS anon_a2d6 ON anon_a2d6.codice = anon_e91a.cod_ruolo LEFT OUTER JOIN 
anagrafica AS anon_f3fb ON anon_f3fb.id = operatore.id_anagrafica ORDER 
BY anagrafica.nome, anon_28bf.id, anon_e91a.id, anon_f3fb.id' {}





some ideas?


Glauco


-- 
++
  Glauco Uri - Programmatore
glauco(at)allevatori.com 
   
  Sfera Carta Software(r)  [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
++



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: multiple mappers on une table problem.

2007-06-11 Thread Michael Bayer


On Jun 11, 2007, at 11:12 AM, Glauco wrote:

>
> This cause a lot of inspiegable problem to property that are perfecly
> functional in the primary
> sqlalchemy.exceptions.ArgumentError: Can't determine relation  
> direction
> for relationship 'Blabla.comune_nascita (Comune)' - foreign key  
> columns
> are present in neither the parent nor the child's mapped tables
>

you need to explicitly specify conditions like primaryjoin,  
foreign_keys, etc.

http://www.sqlalchemy.org/docs/ 
adv_datamapping.html#advdatamapping_properties_customjoin



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: SQLError.... label Error

2007-06-11 Thread Michael Bayer


On Jun 11, 2007, at 11:19 AM, Glauco wrote:

> I use hardly the column prefix, so my query are always aliased.
> this obviously cause a lot of problem whith the order_by clause  
> (that NOT use the same aliases)
>

the approach here depends on how this query is being constructed.  if  
you are using your own alias objects, insert the columns as  
referenced from the alias object itself into the order_by clause.

alias = mytable.alias('foo')
alias.select(order_by=[alias.c.bar])



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] SQLError.... label Error

2007-06-11 Thread Glauco
I use hardly the column prefix, so my query are always aliased.
this obviously cause a  lot of problem whith the order_by clause (that 
NOT use the same aliases)


Is there  some solution or mus wait for the new relase?




This is a tipical Example ...
the anagrafica.nome ORDER_BY column don't work bu SA know how to use 
correclty the alias... beacause the ProgrammingError is correct.

SQLError: (ProgrammingError) invalid reference to FROM-clause entry for 
table "anagrafica"
HINT:  Perhaps you meant to reference the table alias "anon_f3fb".

SELECT
operatore.data_inizio_attivita AS operatore_data_inizio_attivita,
operatore.password AS operatore_password,
operatore.logname AS operatore_logname,
operatore.id_anagrafica AS operatore_id_anagrafica,
operatore.data_fine_attivita AS operatore_data_fine_attivita,
operatore.zoperoles AS operatore_zoperoles,

anon_4877.ts_ultima_modifica AS anon_4877_ts_ultima_modifica,
anon_4877.id AS anon_4877_id,
anon_4877.id_anagrafica AS anon_4877_id_anagrafica,
anon_4877.id_operatore AS anon_4877_id_operatore,
anon_4877.data_inizio AS anon_4877_data_inizio,
anon_4877.bdn_data_ultima_modifica AS anon_4877_bdn_data_ultima_modifica,
anon_4877.bdn_id AS anon_4877_bdn_id,
anon_4877.codice_struttura AS anon_4877_codice_struttura,
anon_4877.id_azienda AS anon_4877_id_azienda,
anon_4877.stato_record AS anon_4877_stato_record,
anon_4877.bdn_specie AS anon_4877_bdn_specie, anon_4877.id_precedente AS 
anon_4877_id_precedente, anon_4877.bdn_flag_carne_latte AS 
anon_4877_bdn_flag_carne_latte,
anon_4877.data_fine AS anon_4877_data_fine, operatore.id AS operatore_id,

anon_a2d6.codice AS anon_a2d6_codice,
anon_a2d6.descrizione AS anon_a2d6_descrizione,
anon_a2d6.group_id AS anon_a2d6_group_id,

anon_f3fb.cod_nazionalita AS anon_f3fb_cod_nazionalita,
anon_f3fb.id AS anon_f3fb_id, anon_f3fb.id_comune AS anon_f3fb_id_comune,
anon_f3fb.cod_professione AS anon_f3fb_cod_professione,
anon_f3fb.dato_fiscale AS anon_f3fb_dato_fiscale,
anon_f3fb.localita AS anon_f3fb_localita,
anon_f3fb.telefono AS anon_f3fb_telefono,
anon_f3fb.email AS anon_f3fb_email,
anon_f3fb.nome AS anon_f3fb_nome,
anon_f3fb.tipo AS anon_f3fb_tipo,
anon_f3fb.cod_titolo_studio AS anon_f3fb_cod_titolo_studio,
anon_f3fb.indirizzo AS anon_f3fb_indirizzo,
anon_f3fb.id_precedente AS anon_f3fb_id_precedente,
anon_f3fb.cod_nazione_nascita AS anon_f3fb_cod_nazione_nascita,
anon_f3fb.id_comune_nascita AS anon_f3fb_id_comune_nascita,
anon_f3fb.stato_record AS anon_f3fb_stato_record,
anon_f3fb.id_operatore AS anon_f3fb_id_operatore,
anon_f3fb.cap AS anon_f3fb_cap,
anon_f3fb.ts_ultima_modifica AS anon_f3fb_ts_ultima_modifica,
anon_f3fb.data_nascita AS anon_f3fb_data_nascita

FROM operatore LEFT OUTER JOIN azienda_veterinario AS anon_28bf ON 
anon_28bf.id_veterinario = operatore.id
LEFT OUTER JOIN unita_aziendale AS anon_4877 ON anon_4877.id = 
anon_28bf.id_unita_aziendale
LEFT OUTER JOIN acl AS anon_e91a ON operatore.id = anon_e91a.id_operatore
LEFT OUTER JOIN ruolo AS anon_a2d6 ON anon_a2d6.codice = 
anon_e91a.cod_ruolo
LEFT OUTER JOIN anagrafica AS anon_f3fb ON anon_f3fb.id = 
operatore.id_anagrafica

ORDER BY *_anagrafica.nome_*, anon_28bf.id, anon_e91a.id, anon_f3fb.id'





-- 
++
  Glauco Uri - Programmatore
glauco(at)allevatori.com 
   
  Sfera Carta Software(r)  [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
++



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] multiple mappers on une table problem.

2007-06-11 Thread Glauco

Hi Folk, I'm finding difficult implement this features of SA .

The example is:  a simple table with a column "type".  I want to do a 
secondary mapper based on the primary mapper with the only different in 
the column type='something'


create table person(
   name text,
   type text);


class Person ( Obj ):
pass
assign_mapper(context,
  Person,
  tbl['person'],
  column_prefix = 'person_',
  extension = SelectResultsExt(),
  properties = {
bla bla
  })


class Blonde( Person ):
  pass

assign_mapper(context,
  Blonde,
  select( [tbl['anagrafica']], tbl['anagrafica'].c.tipo == 
'P').alias('blonde'),
  non_primary = True,
  )



This cause a lot of inspiegable problem to property that are perfecly 
functional in the primary
sqlalchemy.exceptions.ArgumentError: Can't determine relation direction 
for relationship 'Blabla.comune_nascita (Comune)' - foreign key columns 
are present in neither the parent nor the child's mapped tables



Some ideas?


Glauco

















-- 
++
  Glauco Uri - Programmatore
glauco(at)allevatori.com 
   
  Sfera Carta Software(r)  [EMAIL PROTECTED]
  Via Bazzanese,69  Casalecchio di Reno(BO) - Tel. 051591054 
++



--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---



[sqlalchemy] Re: Problems trying to run a query - typeerror

2007-06-11 Thread Michael Bayer

SQLAlchemy doesnt expect your class to have customizations going on  
with  __new__().  either fix your __new__() method to require only  
the cls argument, or create a MapperExtension that provides the  
create_instance() method, so that you create new instances yourself:

http://www.sqlalchemy.org/docs/ 
adv_datamapping.html#advdatamapping_extending


On Jun 10, 2007, at 3:36 PM, nathan harmston wrote:

> HI,
>
> I m currently trying to build an api for a database and I really  
> like the way that Djangos manager ( Class_name.objects ). This  
> seems very intuitive for me. After reading through the some of the  
> django source and getting slightly confused I ve implemented a  
> basic version for one of my tables. The problem is I get an  
> exception, when I m not expecting one. If this isnt a specific  
> sqlalchemy question then please tell me so I can re-post to python  
> etc.
>
> registry.py --> contains table definitions etc.
>
> Manager.py
>
> from Registry import *
>
> class Manager(object):
> def __init__(self, model, table=None):
> self.model = model
> self.table = table
> def get(self, slice):
> pass
> def all(self):
> print "1"
> mapper(self.model, interpro_table)
> print "2"
> session = create_session()
> print "3"
> query = session.query(self.model)
> print "4"
> return query.select()
>
> Models.py
>
> from Manager import *
>
> class ModelBase(type):
> def __new__(cls, name, bases, dict):
> print cls
> setattr(cls, 'objects', Manager(cls))
> return type.__new__(cls, name, bases, dict)
>
> class Model(object):
> __metaclass__=ModelBase
>
> class InterPro(Model):
> _tableName = interpro_table
> def __init__(self, interpro_ac):
> self.interpro_ac = interpro_ac
> def __str__(self):
> return "InterPro: %s" %(self.interpro_ac)
> def __repr__(self):
> return "InterPro: %s" %(self.interpro_ac)
>
> if __name__=='__main__':
> a = Manager(InterPro)
> print a
> print a.all() --> this prints out all of the objects in the  
> database
> i = InterPro('IPR014697')
> print InterPro.objects
> print InterPro.objects.all()
>  --> this fails and produces the exception.
>
> Traceback (most recent call last):
>   File "Model.py ", line 28, in ?
> print InterPro.objects.all()
>   File "/home/skeg/workspace/test/src/Manager.py", line 17, in all
> return query.select()
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",  
> line 247, in select
> return self.select_whereclause(whereclause=arg, **kwargs)
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",  
> line 252, in select_whereclause
> return self._select_statement(statement, params=params)
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",  
> line 378, in _select_statement
> return self.execute(statement, params=params, **kwargs)
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",  
> line 310, in execute
> return self.instances(result, **kwargs)
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/query.py",  
> line 329, in instances
> self.mapper._instance(context, row, result)
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/mapper.py",  
> line 1213, in _instance
> instance = self._create_instance(context.session)
>   File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/mapper.py",  
> line 1234, in _create_instance
> obj = self.class_.__new__(self.class_)
> TypeError: __new__() takes exactly 4 arguments (1 given)
>
> Does anyone know what the problem is? Is it the way I ve programmed  
> this using metaclasses or is it sqlalchemy and the way in  
> instantiates objects or even both?
>
> Many Thanks in advance,
>
> Nathan
>
> >


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~--~~~~--~~--~--~---