Thread: [SQLObject] by<Columnname> method for ForeignKey column
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ksenia M. <ks...@ks...> - 2004-10-28 23:47:46
|
Hi all, I have a table with unique ForeignKey, because it has one-to-one relationship with another table: class Question(SQLObject): question = StringCol() component = ForeignKey('Component', alternateID=True, cascade=True) But Question.byComponent() doesn't work: AttributeError: type object 'Question' has no attribute 'byComponent' Shouldn't it be used that way? Sorry if I am missing something, it's kind of late and this is my first application with SQLObject. BTW, it's an amaizingly cool component that saves a lot of boring work :) Many thanks to Ian Bicking for creating it. Ksenia. |
From: Charles B. <li...@st...> - 2004-10-29 00:51:48
|
Ksenia, I've never tried using a ForeignKey as an alternateID too. There is probably a more elegant way, but in this case I usually just use a select. If you want to select a given question based on the component, you can do something like: qs = Question.select(Question.q.componentID==c.id) if qs.count(): q = qs[0] HTH, -Charles. ----- Original Message ----- From: "Ksenia Marasanova" <ks...@ks...> To: "SQLObject discussion" <sql...@li...> Sent: Thursday, October 28, 2004 6:47 PM Subject: [SQLObject] by<Columnname> method for ForeignKey column > Hi all, > > I have a table with unique ForeignKey, because it has one-to-one > relationship with another table: > > class Question(SQLObject): > question = StringCol() > component = ForeignKey('Component', alternateID=True, cascade=True) > > But Question.byComponent() doesn't work: > AttributeError: type object 'Question' has no attribute 'byComponent' > > Shouldn't it be used that way? Sorry if I am missing something, it's > kind of late and this is my first application with SQLObject. > > BTW, it's an amaizingly cool component that saves a lot of boring work > :) Many thanks to Ian Bicking for creating it. > > Ksenia. > > > > ------------------------------------------------------- > This Newsletter Sponsored by: Macrovision > For reliable Linux application installations, use the industry's leading > setup authoring tool, InstallShield X. Learn more and evaluate > today. http://clk.atdmt.com/MSI/go/ins0030000001msi/direct/01/ > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > |