Re: [Zope-dev] relations in objects

2003-10-10 Thread Paul Winkler
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.

-- 

Paul Winkler
http://www.slinkp.com

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )


RE: [Zope-dev] relations in objects

2003-10-10 Thread Tres Seaver
On Fri, 2003-10-10 at 05:51, Bjorn Stabell wrote:

  From: Paul Winkler [mailto:[EMAIL PROTECTED] 
  On Thu, Oct 09, 2003 at 08:46:24PM -0700, Jason Corbett wrote:
  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.
 
 I am often confused by this as well.  I think, however, that you can
 also reach objects by its object id oid.  If I just use simple
 assignment of a variable to an object in Zope, I get that object's oid,
 right?

Yes, but only at the ZODB level, and only if the contained object
derives from Persistent.  From the application's point of view, OIDs are
irrelevant and useless:  there is no API for manipulating them sanely.

For example:

  from OFS.SimpleItem import SimpleItem # derives from Persistent

  class Foo( SimpleItem ):
  pass

  owning = Foo()

  owned = Foo()

  owning.owned = owned

While it is true that the ZODB will pickle only the OID of 'owned'
within the dict of 'owning', the application doesn't need or want to
manipulate the OID, because it can just refer to 'owning.owned'.

This kind of reference is conceptually like a hard link in a
traditional Unix filesystem;  the same file can be stored in multiple
directories, because the directory contains only a mapping of filename
to inode (OID).

The analog for a symlink would be to store a path to the object, and
then use '{,un}restrictedTraverse' to fetch the object when needed. 
There are a number of products available which try to make such
symlinks more transparent to the application;  it is, however, harded
to make this work cleanly in the general case.

Tres.
-- 
===
Tres Seaver[EMAIL PROTECTED]
Zope Corporation  Zope Dealers   http://www.zope.com


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )


RE: [Zope-dev] relations in objects

2003-10-10 Thread Simon Pamies

Hi Jason,

if you want to deal with references and unique ids and that stuff, feel
free to take a look at http://plone.org/development/current/projects/Ticle
and perhaps to contribute your ideas or even sourcecode.

-sp


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )


Re: [Zope-dev] relations in objects

2003-10-10 Thread Dieter Maurer
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 physicalPaths.

  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

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )


Re: [Zope-dev] relations in objects

2003-10-09 Thread Paul Winkler
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.

-- 

Paul Winkler
http://www.slinkp.com
Look! Up in the sky! It's THE MAN!
(random hero from isometric.spaceninja.com)

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )


Re: [Zope-dev] relations in objects

2003-10-09 Thread mlong
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  -  [EMAIL PROTECTED]
 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 )



___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )


Re: [Zope-dev] relations in objects

2003-10-09 Thread Jason Corbett
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


--- [EMAIL PROTECTED] 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
  http://shopping.yahoo.com
 
  ___
  Zope-Dev maillist  -  [EMAIL PROTECTED]
  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 )
 
 


=
.   _ ___   
   /  __//  /  (_)__  __   __
  /  /_/ __  / /__/ / _ \/ // /\ \/ /   
 /_//_/ //_/_//_/\_,_/ /_/\_\  
 /_/ === 
   Caldera OpenLinux

__
Do you Yahoo!?
The New Yahoo! Shopping - with improved product search
http://shopping.yahoo.com

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )


Re: [Zope-dev] relations in objects

2003-10-09 Thread Leonardo Rochael Almeida
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 :-)


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )


Re: [Zope-dev] relations in objects

2003-10-09 Thread Jason Corbett
  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 [EMAIL PROTECTED] 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

___
Zope-Dev maillist  -  [EMAIL PROTECTED]
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 )