At 08:32 PM 4/30/2001 -0500, Ian Bicking wrote:
>Anyway, I have two classes, one which is the container for another:
>
>Portfolio contains Pieces, (as in .pieces()), and Pieces have a
>reference to portfolio (as in .portfolio()).
>
>If I move a piece between portfolios, the .pieces() will be
>inaccurate, since it seems to cache these backreferences as
>self._pieces.
Yeah, I never dealt with moving objects between 2 lists before. e.g., not
in the test suite.
Seems like we need a removeFromPieces()
>Are these objects unique? Like, if I fetch the same object from the
>store twice, will they be equal (i.e., portfolio1 is portfolio2)?
Yes. This is called "uniquing" and MK does it.
>If so, should the generated code be such that:
>
>class Portfolio:
> def _removePiece(self, piece):
> """Semi-private because it must be called along with
> setPortfolio or self._pieces will be incorrect"""
> if self._pieces is not None:
> self._pieces.remove(piece)
>
>class Piece:
> def setPortfolio(self, portfolio):
> if self._portfolio is not None:
> self._portfolio._removePiece(self)
> self._portfolio = portfolio
>
>Except for all the asserts, and (I guess?) something where you can use
>objectRefs instead of the actual objects...? Maybe there needs to be
>a weak-fetch from the store, so that Piece can fetch its actual
>portfolio if it's been instantiated (in which case it may have an
>invalid cache), but if it hasn't then it doesn't matter.
I'd have to think about it some more. Geoff and I, in private discussions,
reworked the design for MKs list support. We need to enhance that with
moving an object between lists and then post it as a WEP for review.
My feeling is it needs to be tackled as a mini-project so that we nail down
all the semantics simultaneously and back them up with regression tests.
>And on a slightly related note -- if when I edit a Piece I run this
>method:
>
> def changePiece(self):
> piece = self._piece
> piece.setTitle(self.field('title'))
> piece.setName(self.field('name'))
> piece.setDescription(self.field('description'))
> piece.setDisplayOrder(self.field('displayOrder'))
> piece.setPortfolio(self.store().fetchObject('Portfolio',
> self.field('portfolio')))
> self.store().saveChanges()
> self.write('Changes saved.<p>\n')
>
>And I get this error from MySQLdb:
> Warning: Rows matched: 1 Changed: 1 Warnings: 1
>
>I don't know why MySQLdb even bothers giving an error message this
>lame (well Warning/error message)... but any idea what the warning is
>about, or how I can fix it?
I'm not sure. I spent several hours earlier trying to figure out how to get
MySQL to give me details for a warning. I read a bunch of docs, joined the
mailing list, posted my question, etc. I could never find out.
BTW You could rework some of your code like so:
for name in 'title name description displayOrder'.split():
piece.setAttr(name, self.field(name))
Make sure you are using Webware CVS for this. Obviously this only works for
"simple" attributes.
setAttr() will actually call your setFoo(), setBar(), etc.
(Previous setAttr() was called _set())
-Chuck
|