Re: [sqlalchemy] selects, mappers and foreign keys

2014-05-11 Thread Richard Gerd Kuesters
 

thanks Mike! 

the problem is that the other side is also a selectable, so: 

foo = relationship(Remote, primaryjoin=myselect.c.foo ==
myotherselect.c.bar) 

myselect.c.foo *is* a foreign key to some table primary key that is the
value of myotherselect.c.bar, but i can't figure out why or how to make
foreign keys to be detected, basically because i'm trying to use some
weird postgres queries using recursivity and connect paths, so in the
end the error I always get is: 

/path/to/lib/python2.7/site-packages/sqlalchemy/sql/elements.pyc in
_only_column_elements(element, name)
 3348 raise exc.ArgumentError(
 3349 Column-based expression object expected for argument 
- 3350 '%s'; got: '%s', type %s % (name, element, type(element)))
 3351 return element
 3352 

ArgumentError: Column-based expression object expected for argument
'foreign_keys'; got: 'None', type type 'NoneType' 

perhaps i'm asking too much of everything? :) 

best regards, 

richard. 

Em 2014-05-11 00:01, Michael Bayer escreveu: 

 On May 10, 2014, at 7:13 PM, Richard Gerd Kuesters rich...@humantech.com.br 
 wrote: 
 
 hi all! 
 
 situation: i'm mapping a select as a class, using mapper. so far so good. 
 
 problem: some of my selected columns *are* foreign keys in their respective 
 tables, but i would like to say to sqla that they're foreign keys to another 
 mapped class, which have the pks from which those fks are pointing. 
 
 the first question is: how? or
 
 should be able to use relationship(), set up primaryjoin with foreign() 
 
 foo = relationship(Remote, primaryjoin=myselect.c.foo == 
 foreign(table.c.foo)) 
 
 it's a little weird i guess, should work out in modern versions 
 
 the second question: is there a way to inherit properties (like fks) OR 
 cheat declaring foreign keys that doesn't exists at the database level ?
 
 sure, use ForeignKey() on your Column(), doesn't matter if it's not in the 
 DB, or use in relationship foreign_keys / foreign() annotation 
 
 my best regards, 
 
 richard.
 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] selects, mappers and foreign keys

2014-05-11 Thread Michael Bayer

On May 11, 2014, at 10:38 AM, Richard Gerd Kuesters rich...@humantech.com.br 
wrote:

 thanks Mike!
 
 the problem is that the other side is also a selectable, so:
 
 foo = relationship(Remote, primaryjoin=myselect.c.foo == 
 myotherselect.c.bar)
 
 

so again, i can see this might have issues, but in theory (meaning, if it 
doesn't work, I should be able to make it work), it would be:

foo = relationship(Remote, primaryjoin=myselect.c.foo == 
remote(foreign(myotherselect.c.bar)))



-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] selects, mappers and foreign keys

2014-05-11 Thread Richard Gerd Kuesters
 

thanks Mike, that worked fine. my code, though, didn't went further
(i'll have to debug a little bit more) :) 

best regards, 

richard. 

Em 2014-05-11 14:43, Michael Bayer escreveu: 

 On May 11, 2014, at 10:38 AM, Richard Gerd Kuesters 
 rich...@humantech.com.br wrote: 
 
 thanks Mike! 
 
 the problem is that the other side is also a selectable, so: 
 
 foo = relationship(Remote, primaryjoin=myselect.c.foo == 
 myotherselect.c.bar)
 
 so again, i can see this might have issues, but in theory (meaning, if it 
 doesn't work, I should be able to make it work), it would be: 
 
 foo = relationship(Remote, primaryjoin=myselect.c.foo == 
 remote(foreign(myotherselect.c.bar)))

 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


[sqlalchemy] selects, mappers and foreign keys

2014-05-10 Thread Richard Gerd Kuesters
 

hi all! 

situation: i'm mapping a select as a class, using mapper. so far so
good. 

problem: some of my selected columns *are* foreign keys in their
respective tables, but i would like to say to sqla that they're foreign
keys to another mapped class, which have the pks from which those fks
are pointing. 

the first question is: how? or 

the second question: is there a way to inherit properties (like fks) OR
cheat declaring foreign keys that doesn't exists at the database level
? 

my best regards, 

richard. 

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.


Re: [sqlalchemy] selects, mappers and foreign keys

2014-05-10 Thread Michael Bayer

On May 10, 2014, at 7:13 PM, Richard Gerd Kuesters rich...@humantech.com.br 
wrote:

 hi all!
 
 situation: i'm mapping a select as a class, using mapper. so far so good.
 
 problem: some of my selected columns *are* foreign keys in their respective 
 tables, but i would like to say to sqla that they're foreign keys to another 
 mapped class, which have the pks from which those fks are pointing.
 
 the first question is: how? or
 

should be able to use relationship(), set up primaryjoin with foreign()

foo = relationship(Remote, primaryjoin=myselect.c.foo == 
foreign(table.c.foo))

it's a little weird i guess, should work out in modern versions 


 the second question: is there a way to inherit properties (like fks) OR 
 cheat declaring foreign keys that doesn't exists at the database level ?
 
 

sure, use ForeignKey() on your Column(), doesn't matter if it's not in the DB, 
or use in relationship foreign_keys / foreign() annotation





  
 my best regards,
 
 richard.
 
 
 -- 
 You received this message because you are subscribed to the Google Groups 
 sqlalchemy group.
 To unsubscribe from this group and stop receiving emails from it, send an 
 email to sqlalchemy+unsubscr...@googlegroups.com.
 To post to this group, send email to sqlalchemy@googlegroups.com.
 Visit this group at http://groups.google.com/group/sqlalchemy.
 For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
sqlalchemy group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/d/optout.