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
At 02:59 PM 2/19/01 +0100, Christian Scholz wrote:
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?
You need to use an attribute which the object has *if and only if* it exists in the database. If the class has the attribute defined, all instances exist, and you can't even load it with SkinScript because ZPatterns uses __getattr__ to redefine attributes, and that doesn't work if the attribute already exists in the class.
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)).
Right. The load attribute has to be one defined in a provider, and which will end up being "NOT_FOUND" if the object doesn't exist in the table you're querying.
participants (2)
-
cs@comlounge.net -
Phillip J. Eby