Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Tables not forming a relationship properly
Message
From
16/07/2003 17:23:14
Gerry Schmitz
GHS Automation Inc.
Calgary, Alberta, Canada
 
 
To
16/07/2003 09:57:08
Brian Weber
Ohio Department of Development
Columbus, Ohio, United States
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00810631
Message ID:
00810848
Views:
42
The way relations work in VFP (ie. 1-1 vs 1-M) isn't particularly intuitive; especially if one is already familiar with conventional database theory.

I'm including a sample that will at least give you some idea of what you should expect to "see" when dealing with, and navigating, VFP relations ... you might find that you really wanted a "1-1" relation when you thought you wanted "1-M" (and vise versa).

One thing to note is that this sample uses "Grids" and child Grids "respect" their parents when you navigate in a child Grid (ie. they don't wander among other parents); using relations and "only" Forms, you often have to use the SET KEY command when you SELECT and navigate a child table so that it respects its parent; eg.

SET KEY TO [parent key] IN [child table]

(This needs to be done each time the "current" Parent record changes)
*//////////////////////////////////////////////////////////////////
*  Setup.
*//////////////////////////////////////////////////////////////////
   CREATE CURSOR invoices (cno c(5), ino N(4,0))
   INSERT INTO invoices (cno, ino) VALUES ("B9278",1106)
   INSERT INTO invoices (cno, ino) VALUES ("B9278",1107)

   CREATE CURSOR detail (ino N(4,0), pno c(5))
   INSERT INTO detail (ino, pno) VALUES (1107,"AAAAA")
   INSERT INTO detail (ino, pno) VALUES (1107,"BBBBB")
   INSERT INTO detail (ino, pno) VALUES (1107,"CCCCC")
   INSERT INTO detail (ino, pno) VALUES (1106,"AAAAA")
   INSERT INTO detail (ino, pno) VALUES (1106,"BBBBB")

   SELECT detail
   INDEX ON ino TAG ino
   SET ORDER TO ino

   SELECT invoices
   INDEX ON cno TAG cno
   SET ORDER TO cno

   SET VIEW ON

*//////////////////////////////////////////////////////////////////
*  "1-M" Relation.
*//////////////////////////////////////////////////////////////////
   WAIT WINDOW "(1-M) Notice how the relation looks in the view"+ ;
     CHR(13)+"Press ESC to continue" NOWAIT

   SELECT invoices
   SET RELATION TO ino INTO detail
   SET SKIP TO detail               && NOTE: "1-M" ?!

   SELECT invoices
   LOCATE
   BROWSE FIELDS invoices.ino, detail.pno NOWAIT

   ACTIVATE WINDOW invoices

   ON KEY LABEL ESC CLEAR EVENTS
   READ EVENTS
   ON KEY LABEL ESC

   RELEASE WINDOWS Invoices

*//////////////////////////////////////////////////////////////////
*  "1-1" Relation.
*//////////////////////////////////////////////////////////////////
   WAIT WINDOW "(1-1) Notice how the relation looks in the view"+ ;
     CHR(13)+"Press ESC to continue" NOWAIT

   SELECT invoices
   SET RELATION TO ino INTO detail
   SET SKIP TO                && NOTE: "1-1" ?!

   SELECT invoices
   LOCATE
   BROWSE FIELDS invoices.ino, detail.pno ;
      NAME o_Browse1 NOWAIT

   SELECT detail
   BROWSE FIELDS invoices.ino, detail.pno ;
      NAME o_Browse2 NOWAIT

   o_Browse1.Height = 200
   o_Browse2.Top    = 200
   o_Browse2.Height = 200

   ACTIVATE WINDOW invoices

   ON KEY LABEL ESC CLEAR EVENTS
   READ EVENTS
   ON KEY LABEL ESC
   CLEAR ALL

*//////////////////////////////////////////////////////////////////
*  EOF.
*//////////////////////////////////////////////////////////////////
>I'm still a little new to FoxPro, and having issues linking tables together. I have two tables, set up with an appropriate automaticly defined primary key(numerical field, with a default value of "recno()" ), and FoxPro wont let me create any relationship between the two table except a one to one relationship, which is not what i want, and besides that it doesnt work right. I need a one to many relationship. On top of this, FoxPro is working just fine pulling data from the one table, yet will only pull one record from the other(its not updating the form at all), despite the query changing for both tables. Im not sure really how to explain it clearly, but thats the best way to describe it i can come up with. Any suggestions on how to fix this would be welcome
> Brian
Previous
Reply
Map
View

Click here to load this message in the networking platform