Forum OpenACS Development: new CrClass description issue
hy there,
i have new class for creating,... products, writen in xotcl
the code is bellow:
and if i want to create new item in db. i use this code.
for example:
and the error that i'm getting is
how should i set description var. ?
Code:
the code is bellow:
and if i want to create new item in db. i use this code.
for example:
::im::Product create product ::product set name "New product test name" ::product set title "New product test title" ::product set description "New product test description" ::product set price "11" ::product set delivery_time "10" ::product save_new
and the error that i'm getting is
how should i set description var. ?
ERROR:
can't read "description": no such variable
while executing
"::xo::db::sql::content_item new -name $name -parent_id $parent_id -creation_user $creation_user -creation_ip $creation_ip -item_subtype "content_ite..."
("eval" body line 1)
invoked from within
"eval ::xo::db::sql::content_item new [[self class] set content_item__new_args]"
invoked from within
"set item_id [eval ::xo::db::sql::content_item new [[self class] set content_item__new_args]]"
("uplevel" body line 16)
invoked from within
"uplevel 1 $transaction_code "
(procedure "db_transaction" line 39)
invoked from within
"db_transaction {
$__class instvar storage_type object_type
[self class] lock acs_objects "SHARE ROW EXCLUSIVE"
set revision_id [db_n..."
(procedure "save_new" line 30)
invoked from within
"next"
(procedure "save_new" line 3)
::product ::xo::db::CrCache::Item->save_new
invoked from within
"::product save_new"
("uplevel" body line 7)
invoked from within
"uplevel 1 [string map {"\\\r\n" " "} $script]"
Code:
namespace eval ::im {
::xo::db::CrClass create ::im::Product \
-superclass ::xo::db::CrItem \
-id_column product_id \
-table_name im_products \
-pretty_namne "Im Product"
::im::Product instproc init {} {
my instvar product_id name title description company_id price delivery_time
next
my slots {
::xo::db::CtAttribute create company_id \
-datatype integer \
-pretty_name "Company ID" \
-pretty_plural "Company IDs"
::xo::db::CrAttribute create price \
-pretty_name "Product Price" \
-pretty_plural "Product Prices"
::xo::db::CrAttribute create delivery_time \
-datatype date \
-pretty_name "Product Delivery Time" \
-pretty_plural "Product Delivery Times"
}
}
::im::Product ad_instproc save_new {} {
my instvar product_id name title description company_id price delivery_time
next
}
::im::Product ad_instproc save {} {
my instvar product_id name title description company_id price delivery_time
next
}
}
Tim,
"and the error that i'm getting is
how should i set description var. ?"
this leds you up the garden path. I verified your declaration of
::im::product which is not supposed to work anyway, leaving aside
creating and persisting instances thereof. Find a working examples
below:
namespace eval ::im {
::xo::db::CrClass create ::im::Product \
-superclass ::xo::db::CrItem \
-id_column product_id \
-table_name im_products \
-pretty_name "Im Product" \
-slots {
::xo::db::CrAttribute create company_id \
-datatype integer \
-pretty_name "Company ID" \
-pretty_plural "Company IDs"
::xo::db::CrAttribute create price \
-pretty_name "Product Price" \
-pretty_plural "Product Prices"
::xo::db::CrAttribute create delivery_time \
-datatype date \
-pretty_name "Product Delivery Time" \
-pretty_plural "Product Delivery Times"
}
}
::im::Product create product \
-name "New product test name" \
-title "New product test title" \
-description "New product test description" \
-price 11 \
-delivery_time "2004-10-19 10:23:54+02"
::product save_new
What are/ were the most burning issues:
1. Slot declaration in product->init(): init is performed on an
instance, i.e. an object of class ::im::product, while slots() is
class-object-specific, i.e. it can only be applied to ::im::product
directly (technically speaking, it is a per-instance method provided
by ::xotcl::Class which is inherited by ::xo::db::CrClass)
2. you got many typos in there: pretty_namne -> pretty_name,
CtAttribute -> CrAttribute
3. finally, if you want something to be a timestamp + time zone, then
you need to provide it: ::product delivery_time "2004-10-19
10:23:54+02"
cheers
//stefan