[Zope-dev] ZPatterns and SQL

Christian Scholz cs@comlounge.net
Mon, 19 Feb 2001 14:59:18 +0100


Hi there!

I have a little problem with my Specialist and DataSkins regarding storage inside
an sql database. Mainly I don't know what to put under the "loading by accessing attribute"
in the Storage tab of the Rack.

I have the following SkinScript:

    WITH QUERY getCustomer(customer_id=self.id) COMPUTE company_name, customer_no

    WHEN OBJECT ADDED CALL addCustomer(
    company_name=self.company_name,
    customer_no=self.customer_no
    )

    WHEN OBJECT CHANGED STORE company_name,customer_no USING
    updateCustomer(customer_id=self.id, 
    company_name=self.company_name,
    customer_no=self.customer_no
    )

I've now set the loadAttrib to "company_name" and retrieving objects works fine.
Unfortunately when doing a newItem() with some random new id (it's not used as the
database should provide the id) I get an error that this id already exists.
Of course I've checked it in the database and it's not there.

After some code reading I found in retrieveItem:

    a = self.loadAttrib
    item = None

    if a:
	item = self._RawItem(key)
	if hasattr(item.aq_base, a):
	    return item

So as the item is an instance of my ZClass containing also an company_name attribute
it will always return the item and because of that the Rack thinks it's already there.
So why is this happening? What do I need to change?

When changing the loadAttrib to something else (non existing), the newItem is working
but instead getItem is not working anymore as it returns None only.. (somehow the zsql
method is not even called thus the skinscript seems not to work in that case (I guess
because the loadAttrib is not defined in it somewhere)).

Does anybody know any help?
(somehow I once had a working specialist with an sql table but I dunno what happened
to make it not work anymore).

My ZPatterns version is the one of stevea and my Zope is 2.3

kind regards,
  Christian

-- 
COM.lounge                                          http://comlounge.net/
communication & design                                 info@comlounge.net