M
mike
i have an Item which belongs to a Category, so Item has:
- item.categoryId, the database primary key of its Category
- item.category, a reference to its Category. this null unless i need a
reference from item to its Category object, in which case i call
setCategory(category)
sometimes i want a list of categories, and from each i want to be able
to access a list of its items. in this case is it considered acceptable
to just create a list of those items and assign it as a property of
their category? eg:
category.items = listOfItems
this packages everything up into a hierarchy and is more convenient to
use, especially in Cheetah templates, but requries modifying the
structure of the object, which bothers me (probably for some
subconscious java-related reason).
the alternative might be to create a dictionary that keys the lists of
items on their category:
items = {}
items[category.id] = listOfItems
this feels less "controversial" to me, but requires extra objects and
house-keeping.
thanks - just curious if there were arguments one way or the other.
- item.categoryId, the database primary key of its Category
- item.category, a reference to its Category. this null unless i need a
reference from item to its Category object, in which case i call
setCategory(category)
sometimes i want a list of categories, and from each i want to be able
to access a list of its items. in this case is it considered acceptable
to just create a list of those items and assign it as a property of
their category? eg:
category.items = listOfItems
this packages everything up into a hierarchy and is more convenient to
use, especially in Cheetah templates, but requries modifying the
structure of the object, which bothers me (probably for some
subconscious java-related reason).
the alternative might be to create a dictionary that keys the lists of
items on their category:
items = {}
items[category.id] = listOfItems
this feels less "controversial" to me, but requires extra objects and
house-keeping.
thanks - just curious if there were arguments one way or the other.