Hello Zope developers,
I'm a newbie (sorry most people have this curse at one point or another). I have read the zope book (or at least most of it), and the zope developer manual. I can't quite figure out how to have relationships between instances of classes in the database.
Let me first ask if I'm using zope for the correct thing. I see that a lot of zope products deal with content management, while mine doesn't really. Basically I want to do what I would normally do with mysql and php, but use zope instead. So I need a way to reference in some intelligent way between objects in zope, and I need a way to query for a list of them.
I read about ZCatalogs, etc and how you can use that for querying and indexing. That isn't my first priority, so I'll worry about that a little later.
Basically I have an instance of a class 'A'. As part of it I need to reference either a single or in some cases multiple instances of class 'B'. Basically I'll have a mix of one-to-one relations and one-to-many. When I'm coding my python class (I'm going to do a product if you can't tell), how would I get a list of the 'B' instances that relate to this object, and how would I store that? The zope developer manual was pretty good for writing classes, and making views on it, but I need to be able to call methods on those instances and return lists of them.
Sorry for the long email, I just don't want to leave details out. If you think I'm barking up the wrong tree, and shouldn't be using zope for this, don't be afraid to let me know. Although I will be pretty disappointed, I think zope is exactly what I've been looking for, I can't find anything like it in any other language.
Jason Corbett
__________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com
On Thu, Oct 09, 2003 at 05:07:28PM -0700, Jason Corbett wrote:
to reference in some intelligent way between objects in zope, and I need a way to query for a list of them.
google for mxmRelations. It does many-to-many relationships so yuo might have to modify it a bit if you really need to constrain that.
Hi Jason,
I am not a zope developer, I am a semi-new user who started with zope coming from the same mindset as yourself. One of the biggest challanges(at least for me) is to wrap your mind around object oriented programming. The zope database is an object oriented database. This means that you will want/need to design your product differently than if you were using mysql/php to present and store your data. Think of the information you want to track as real world objects, and it is. Then think about how these real world objects relate to one another. You will start to see a pattern. Use this pattern to create a hierarchical folder(object) structure. This structure along with python's object inheritance will allow you to develop your relationships. Play with zope. Write your product. Discover that you need to rewrite your product because you did not understand some fundamentals. Complete the rewrite. Rinse and repeat until you get it right.
Cheers, Mike
Hello Zope developers,
I'm a newbie (sorry most people have this curse at one point or another). I have read the zope book (or at least most of it), and the zope developer manual. I can't quite figure out how to have relationships between instances of classes in the database.
Let me first ask if I'm using zope for the correct thing. I see that a lot of zope products deal with content management, while mine doesn't really. Basically I want to do what I would normally do with mysql and php, but use zope instead. So I need a way to reference in some intelligent way between objects in zope, and I need a way to query for a list of them.
I read about ZCatalogs, etc and how you can use that for querying and indexing. That isn't my first priority, so I'll worry about that a little later.
Basically I have an instance of a class 'A'. As part of it I need to reference either a single or in some cases multiple instances of class 'B'. Basically I'll have a mix of one-to-one relations and one-to-many. When I'm coding my python class (I'm going to do a product if you can't tell), how would I get a list of the 'B' instances that relate to this object, and how would I store that? The zope developer manual was pretty good for writing classes, and making views on it, but I need to be able to call methods on those instances and return lists of them.
Sorry for the long email, I just don't want to leave details out. If you think I'm barking up the wrong tree, and shouldn't be using zope for this, don't be afraid to let me know. Although I will be pretty disappointed, I think zope is exactly what I've been looking for, I can't find anything like it in any other language.
Jason Corbett
Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com
Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
Thanks for your reply. I've actually been thinking in an object oriented form for a while. I've looked at implimenting this project in Java using either prevailance or a object persistence model that mapped to a RDBMS. I like the idea of zope, so maybe I should clarify my question:
How does an object in zope know where it sits in the hirearchy, and how does it reach other objects. That's what I'm really looking for, I can probably code the rest of the parts.
Jason Corbett
--- mlong@datalong.com wrote:
Hi Jason,
I am not a zope developer, I am a semi-new user who started with zope coming from the same mindset as yourself. One of the biggest challanges(at least for me) is to wrap your mind around object oriented programming. The zope database is an object oriented database. This means that you will want/need to design your product differently than if you were using mysql/php to present and store your data. Think of the information you want to track as real world objects, and it is. Then think about how these real world objects relate to one another. You will start to see a pattern. Use this pattern to create a hierarchical folder(object) structure. This structure along with python's object inheritance will allow you to develop your relationships. Play with zope. Write your product. Discover that you need to rewrite your product because you did not understand some fundamentals. Complete the rewrite. Rinse and repeat until you get it right.
Cheers, Mike
Hello Zope developers,
I'm a newbie (sorry most people have this curse
at
one point or another). I have read the zope book
(or
at least most of it), and the zope developer
manual.
I can't quite figure out how to have relationships between instances of classes in the database.
Let me first ask if I'm using zope for the
correct
thing. I see that a lot of zope products deal
with
content management, while mine doesn't really. Basically I want to do what I would normally do
with
mysql and php, but use zope instead. So I need a
way
to reference in some intelligent way between
objects
in zope, and I need a way to query for a list of
them.
I read about ZCatalogs, etc and how you can use
that
for querying and indexing. That isn't my first priority, so I'll worry about that a little later.
Basically I have an instance of a class 'A'. As part of it I need to reference either a single or
in
some cases multiple instances of class 'B'.
Basically
I'll have a mix of one-to-one relations and one-to-many. When I'm coding my python class (I'm going to do a product if you can't tell), how
would I
get a list of the 'B' instances that relate to
this
object, and how would I store that? The zope developer manual was pretty good for writing
classes,
and making views on it, but I need to be able to
call
methods on those instances and return lists of
them.
Sorry for the long email, I just don't want to
leave
details out. If you think I'm barking up the
wrong
tree, and shouldn't be using zope for this, don't
be
afraid to let me know. Although I will be pretty disappointed, I think zope is exactly what I've
been
looking for, I can't find anything like it in any other language.
Jason Corbett
Do you Yahoo!? The New Yahoo! Shopping - with improved product
search
Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
===== . _____ ___ / __/____/ / (_)__ __ ____ __ / /_/ __ / /__/ / _ / // /\ / / /_____//_/ /____/_/_//_/_,_/ /_/_\ ==== /_____/ =================================== Caldera OpenLinux
__________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com
On Fri, 2003-10-10 at 00:46, Jason Corbett wrote:
Thanks for your reply. I've actually been thinking in an object oriented form for a while. I've looked at implimenting this project in Java using either prevailance or a object persistence model that mapped to a RDBMS. I like the idea of zope, so maybe I should clarify my question:
How does an object in zope know where it sits in the hirearchy, and how does it reach other objects. That's what I'm really looking for, I can probably code the rest of the parts.
In my experience, you should put an object inside another if and only if they have an explicit containment relationship, e.g. a car has 4 tires and a steering wheel. The steering wheel can belong to (at most) one car at any moment in time, so it would make sense to put the steering wheel object inside the car object. The same is not true of, for instance, students and school classes. In this case you either store a reference to the student in the school class (eg a student id in a "lines" or "tokens" property) or you create an object to represent the class-student relationship (for example an enrollment) and store it somewhere.
Tip: always use methods that return the objects you need, for instance aSchoolClass.students() this way you can more easily change the storage of the relationship information when you change your mind. And you will change your mind a lot of times.
Tip2: a lot of times you'll implement the above mentioned methods as catalog queries, like: what objects in the other side of the relationship reference me?
Tip3: look mxmRelations
Cheers, Leo
PS: just because this is a pet peeve of mine, I'll explain that a "relation" and a "relationship" are two very different things. "Relation" is the mathematical term for a table, a set of distinct elements (rows) with the same kinds of attributes (columns). You can think of a relation (table) of cars, or a relation (table) of students. Relational databases get their names because they store relations and allow you to do some relational algebra with (usually) SQL.
A relationship, on the other hand, is a link, or association, between elements.
RDBs allow you to model relationships relatively easily thru either relational operations:
SELECT * from cars, steering_wheels WHERE steering_wheels.carId = car.carId AND steering_wheels.wheelType = "sport"
or by storing relationship information in relations (sometimes known as "link relations" or "link tables"):
SELECT * from enrollments, classes, students WHERE classes.classId = enrollments.classId AND enrollments.studentId = students.studentId AND students.studentName = "Jason Corbett"
But RDBs themselves have absolutely no concept of "relationships".
So, next time you read the word "relation", think "table" :-)
I'm sorry for my ignorant use of the terms relation and relationship. I'll try to use the terms more appropriately in the future.
I think I understand where I've become confused. In many of the persistance mechanisms I've looked at references to other objects were handled specially, and had rules associated with them. I think I understand now that it is mearly just a design problem, nothing having to do with zope. When creating objects I will need to pass the reference to the other object, or have a manager for the relationship.
I had assumed that objects were somehow self aware in some way of the zope environment, and therefore coule access it. I appologize for any time I might have wasted. The solution is simpler than I had thought.
Jason Corbett
--- Leonardo Rochael Almeida leo@hiper.com.br wrote:
On Fri, 2003-10-10 at 00:46, Jason Corbett wrote:
Thanks for your reply. I've actually been
thinking in
an object oriented form for a while. I've looked
at
implimenting this project in Java using either prevailance or a object persistence model that
mapped
to a RDBMS. I like the idea of zope, so maybe I should clarify my question:
How does an object in zope know where it sits in
the
hirearchy, and how does it reach other objects. That's what I'm really looking for, I can probably code the rest of the parts.
In my experience, you should put an object inside another if and only if they have an explicit containment relationship, e.g. a car has 4 tires and a steering wheel. The steering wheel can belong to (at most) one car at any moment in time, so it would make sense to put the steering wheel object inside the car object. The same is not true of, for instance, students and school classes. In this case you either store a reference to the student in the school class (eg a student id in a "lines" or "tokens" property) or you create an object to represent the class-student relationship (for example an enrollment) and store it somewhere.
Tip: always use methods that return the objects you need, for instance aSchoolClass.students() this way you can more easily change the storage of the relationship information when you change your mind. And you will change your mind a lot of times.
Tip2: a lot of times you'll implement the above mentioned methods as catalog queries, like: what objects in the other side of the relationship reference me?
Tip3: look mxmRelations
Cheers, Leo
PS: just because this is a pet peeve of mine, I'll explain that a "relation" and a "relationship" are two very different things. "Relation" is the mathematical term for a table, a set of distinct elements (rows) with the same kinds of attributes (columns). You can think of a relation (table) of cars, or a relation (table) of students. Relational databases get their names because they store relations and allow you to do some relational algebra with (usually) SQL.
A relationship, on the other hand, is a link, or association, between elements.
RDBs allow you to model relationships relatively easily thru either relational operations:
SELECT * from cars, steering_wheels WHERE steering_wheels.carId = car.carId AND steering_wheels.wheelType = "sport"
or by storing relationship information in relations (sometimes known as "link relations" or "link tables"):
SELECT * from enrollments, classes, students WHERE classes.classId = enrollments.classId
AND enrollments.studentId = students.studentId AND students.studentName = "Jason Corbett"
But RDBs themselves have absolutely no concept of "relationships".
So, next time you read the word "relation", think "table" :-)
__________________________________ Do you Yahoo!? The New Yahoo! Shopping - with improved product search http://shopping.yahoo.com
Hi,
If this is not the place to report this type of issue I apologize and would ask to be directed to the correct place. I downloaded and installed Zope-2.7.0-b3 for windows. It appears that datetime.pyd is missing from the DLLs directory. I was able to copy this file to this directory from a python 2.3.2 installation and all worked well Was this an oversight when packaging this release?
Cheers, Mike
On Fri, 2003-12-26 at 13:01, Michael Long wrote:
Hi,
If this is not the place to report this type of issue I apologize and would ask to be directed to the correct place. I downloaded and installed Zope-2.7.0-b3 for windows. It appears that datetime.pyd is missing from the DLLs directory. I was able to copy this file to this directory from a python 2.3.2 installation and all worked well Was this an oversight when packaging this release?
The correct place to report such bugs would be the "Zope collector", http://collector.zope.org/Zope. Note that there is an existing bug report about this: http://collector.zope.org/Zope/1128
Tres.
The correct place to report such bugs would be the "Zope collector", http://collector.zope.org/Zope. Note that there is an existing bug report about this: http://collector.zope.org/Zope/1128
Thanks
On Thu, Oct 09, 2003 at 08:46:24PM -0700, Jason Corbett wrote:
Thanks for your reply. I've actually been thinking in an object oriented form for a while. I've looked at implimenting this project in Java using either prevailance or a object persistence model that mapped to a RDBMS. I like the idea of zope, so maybe I should clarify my question:
How does an object in zope know where it sits in the hirearchy,
The only unique identifier that zope provides is the containment path. An object can tell you its containment path by doing foo.absolute_url(1) or foo.getPhysicalPath() depending on what form you want the output in.
and how does it reach other objects.
By path. Zope provides a number of ways to express paths in python:
foo["some"]["path"] # does NOT use acquisition, only containment foo.some.path # uses acquisition getattr(foo.some, "path") # uses acquisition
foo.unrestrictedTraverse("/some/path/from/zope/root") foo.unrestrictedTraverse("some/path/relative/to/foo") (see also restrictedTraverse)
Note that storing a direct reference may be dangerous e.g. you might not have the object you are expecting - in fact it's very likely that you get an acquisition wrapper which may change at any time. On the other hand, storing paths is problematic if you want to be able to move or rename an object and still keep references to it elsewhere. Hence, look at mxmRelations which helps with this.
Jason Corbett wrote at 2003-10-9 20:46 -0700:
... How does an object in zope know where it sits in the hirearchy, and how does it reach other objects.
In fact, the object does not know it.
In Zope, you usually do not deal with the object itself but with an acquisition wrapper. This wrapper represents the object and the way you accessed it. The wrapper is able to tell you a direct path from the root to the object (the so called "physicalPath" of the "object").
However, the same object can be at different places in the Zope hierarchy. Depending on access path, the object than can have different "physicalPath"s.
That's what I'm really looking for, I can probably code the rest of the parts.
You should look at "mxmRelations" as someone else already told you.
Dieter