Re: [SQLObject] a third way of accessing attributes
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Luke O. <lu...@me...> - 2003-05-15 16:10:06
|
Quoting Nick <ni...@dd...>: > Sorry, I forgot to say what my point was :) My point is that it's more > convenient to treat objects as persistent using that kind of model than > have set() and get() functions a la C (java, etc.). You're doing nearly > the exact same thing as properties, so why not use them. I think Bud's point was to use properties (see the end of his example), but the important part was to be able to add Backend 'Mappings' to any arbitrary class (not needing classes to be initially tied to SQLObject or similar). I'm not entirely sure I understand the need for this, but it's intriguing. Actually, out of curiousity, I wanted to see if there was any special reason SQLObject addColumn's in the metaclass: class Answer(CoreObject): _columns = [ TextCol('answer'), ## removed ForeignKey('Question') for this test ] class Question(CoreObject): _columns = [ Col('question') ] _joins = [ MultipleJoin('Answer') ] >>> from Answer import Answer >>> from SQLObject import * >>> col = ForeignKey('Question') >>> Answer.addColumn(col) >>> from Question import Question >>> Answer(2).question <Question 1 question='John'> >>> So, SQLObject currently supports dynamically adding properties at runtime (I guess I knew that...). What we gain by pulling this ability into a helper class (like I assume Mapping to be), that allows us to 'addColumn' to any class we please? ArbitraryClass + Mapping == SQLObjectClass + _columns/_joins, yes? Hmm, intriguing, as I said.. - Luke |