473,386 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Contact Management DB: Handling "Friends"?

I'm makeing a little DB to help manage high school class reunions.

One feature I'm trying to implement is "Friends". e.g. Fred Smith is a friend
of Joe Jones and Bill Anderson. We record that so that when Fred moves and
our mailing bounces, we can call Joe and/or Bill in hopes of getting Fred's new
address.

I started implementing this as just tblFriend linked to tblPerson on PersonID
plus another link to tblPerson on FriendID.

But now I realize that the data is far from Normal. Seems like when I add Joe
Jones as a 'Friend' of Fred Smith, the app should know that the relationship
goes both ways: i.e. Joe shows up on Fred's screen (as expected...) but Fred now
automatically shows up on Joe's screen.

Anybody been here?
--
PeteCresswell
Nov 13 '05 #1
6 2103
Greetings,

I have been there. My fix may be a bit of a kludge but it goes like
this

say that
Fred's ID = A123
Bill's ID = B234
Joe's ID = C345
Sue's ID = D456

tblPeople
MainPersonID, Friend1, Friend2, Friend3, Friend4
A123 B234 C345 D456
B234 A123
C345 A123 D456
D456 A123 C345

Normalized Version of tblPeople
MainPersonID, FriendID
A123 B234
A123 C345
B234 A123
C345 A123
C345 D456
D456 A123
D456 C345

The kludge is that there is no table containing just friend ID's. These
have to be manually associated as in the 2nd tblPeople. I'm sure there
is a way to dynamically associate the ID's. I just haven't come up with
that way. But this is how I handled a similar situation.

HTH

Rich

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 13 '05 #2
(Pete Cresswell) wrote:
I'm makeing a little DB to help manage high school class reunions.

One feature I'm trying to implement is "Friends". e.g. Fred Smith is a friend
of Joe Jones and Bill Anderson. We record that so that when Fred moves and
our mailing bounces, we can call Joe and/or Bill in hopes of getting Fred's new
address.

I started implementing this as just tblFriend linked to tblPerson on PersonID
plus another link to tblPerson on FriendID.

But now I realize that the data is far from Normal. Seems like when I add Joe
Jones as a 'Friend' of Fred Smith, the app should know that the relationship
goes both ways: i.e. Joe shows up on Fred's screen (as expected...) but Fred now
automatically shows up on Joe's screen.

Anybody been here?


No. But you could create a query. Add the Classmates table and Friends
twice. You should now have Friends and Friends_1. Drag a link from
Classmate to Friends on the PersonID on Friends. Then drag a link from
Classmate to FriendID on Friends_1.

Set the relationship to select All records from Classmates and only
matching records from Friends and Friends_1. (dbl=click on relationship
line)

You would want then want to modify the criteria so that you select the
Person from the Classmate file.

You would get the ID from Friends1 where the ID in Friends is not null.
In the next criteria line (OR) , where ID in Friend_1 is not null.

Or...you could modify this so that you UNION it between 2 queries.
Select all records with PersonID matches PersonID and PersonID matches
FriendID.
Nov 13 '05 #3
On Wed, 03 Nov 2004 16:02:29 GMT, "(Pete Cresswell)" <x@y.z> wrote:
I'm makeing a little DB to help manage high school class reunions.

One feature I'm trying to implement is "Friends". e.g. Fred Smith is a friend
of Joe Jones and Bill Anderson. We record that so that when Fred moves and
our mailing bounces, we can call Joe and/or Bill in hopes of getting Fred's new
address.

I started implementing this as just tblFriend linked to tblPerson on PersonID
plus another link to tblPerson on FriendID.

But now I realize that the data is far from Normal. Seems like when I add Joe
Jones as a 'Friend' of Fred Smith, the app should know that the relationship
goes both ways: i.e. Joe shows up on Fred's screen (as expected...) but Fred now
automatically shows up on Joe's screen.

Anybody been here?


I think the best answer is just to create 2 friendship records, one pointing
each way. If you need cascading delete, just set both relationships from
people to friends as cascade delete, and deleting either person, will then
delete both of the friend relations between that person and each of his/her
friends.
Nov 13 '05 #4
Pete:

A half baked idea for you to flesh out...

Assuming two tables

tblPerson
PersonID - pk
PersonName
etc

tblFriend
RelID - pk
PersonID - fk
FriendID - fk

create the following union query:

SELECT tblFriend.PersonID AS Person, tblFriend.FriendID AS Friend
FROM tblFriend UNION ALL SELECT tblFriend.FriendID AS Person,
tblFriend.PersonID AS Friend
FROM tblFriend;

that should get you a list of Person to Friend and the reverse
relationship you are looking for.

Now the half baked part...

I assume you will make a form to show the person data, with a subform
showing friends. The subform will use the union query as the record
source. You will have to manage adding and deleting relationships via
popups since you can't do that directly in the union query. Shouldn't
be a big deal but I'm sure there will be gotchas in there somewhere.

I'd be interested in the gotchas you run across if you use it. If you
don't I'd like to hear why you rejected the approach.

good luck

Tom

"(Pete Cresswell)" <x@y.z> wrote in message news:<91********************************@4ax.com>. ..
I'm makeing a little DB to help manage high school class reunions.

One feature I'm trying to implement is "Friends". e.g. Fred Smith is a friend
of Joe Jones and Bill Anderson. We record that so that when Fred moves and
our mailing bounces, we can call Joe and/or Bill in hopes of getting Fred's new
address.

I started implementing this as just tblFriend linked to tblPerson on PersonID
plus another link to tblPerson on FriendID.

But now I realize that the data is far from Normal. Seems like when I add Joe
Jones as a 'Friend' of Fred Smith, the app should know that the relationship
goes both ways: i.e. Joe shows up on Fred's screen (as expected...) but Fred now
automatically shows up on Joe's screen.

Anybody been here?

Nov 13 '05 #5
I've done this with

tblPeople
PeopleID
First
Last
etc.

tblRelationshipTypes
TypeID
Type (e.g. Friend, brother, employer, etc.)

Then I can record all types of relationships in
tblRelationships
PeopleID
IsRelatedTo (another PeopleID)
IsRelatedAs (use a TYPEID)
also a comment

My main frmPeople has a subform frmsubRelationships - and does a
lookup to Phone for the person also.
This does not do the union mentioned in a previous post, and that's
actually one thing I've been thinking about adding.

First, however, I'd like to solve the problem of adding a new person.
Since my control for "IsRelatedTo" is a dropdown, Not in List will
call a small form just for adding a person, address & phone.
Unfortunately, it often crashes the database. The only reason I can
think of is that frmPeople has tblPeople open already. When I call me
small frmAddPeople, I'm opening another copy of tblPeople. Should I
be opening a RecordsetClone? Will that let me save a new record? Or
is there a way to close the table before closing the pop-up?
Nov 13 '05 #6
RE/
SELECT tblFriend.PersonID AS Person, tblFriend.FriendID AS Friend
FROM tblFriend UNION ALL SELECT tblFriend.FriendID AS Person,
tblFriend.PersonID AS Friend
FROM tblFriend;

that should get you a list of Person to Friend and the reverse
relationship you are looking for.

Now the half baked part...

I assume you will make a form to show the person data, with a subform
showing friends. The subform will use the union query as the record
source. You will have to manage adding and deleting relationships via
popups since you can't do that directly in the union query. Shouldn't
be a big deal but I'm sure there will be gotchas in there somewhere.

I'd be interested in the gotchas you run across if you use it. If you
don't I'd like to hear why you rejected the approach.


Done. Works as advertised.

-----------------------
tblPersonFriend:
PersonFriendID (PK)
PersonID_A
PersonID_B
Comments
-----------------------
The union query returns tblFriend recs where PersonID_A
matches the currently-selected person and where PersonID_B matches same.

I feed the Union query to an Append query that loads that info into a work
table, putting PersonID_A or ..._B into the work table's PersonID as appropriate
and putting the other into FriendID. The subform's combo box's.ControlSource is
FriendID and it's .RowSource is a list of people by PersonID, excluding
whoever's record is currently being edited.

------------------
ttblFriend:
PersonFriendID
PersonID
FriendID
Comments
------------------

When Save time comes around, I run four queries:

- qryPersonSave_Friend1_AppendNew
- qryPersonSave_Friend2_UpdateExisting
- qryPersonSave_Friend3_IdentifyDeleted
- qryPersonSave_Friend4_RemoveDeleted
There's a little more processing with deleted recs.
This comes in the form of another work table that I didn't mention yet:

------------------------
ttblFriendDeleteTracker:
PersonFriendID
IsDeleted
------------------------

Right after I load ttblFriend, I load ttblFriendDeleteTracker
by copying info from the just-loaded ttblFriend.

Then, at Save time, I run an Update query that joins ttblPersonFriend to
ttblPersonFriendDeleteTracker on PersonFriendID and sets IsDeleted=True for recs
that have disappeared from ttblPersonFriend.

After that's done, I run a Delete query that joins ttblPersonFriendDeleteTracker
to tblPersonFriend on PersonFriendID and deletes tblPersonFriend recs where
IsDeleted=True.
Sounds like a lot of code, but it's pretty simple and executes in a flash.

Thanks.
--
PeteCresswell
Nov 13 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

93
by: jacob navia | last post by:
In this group there is a bunch of people that call themselves 'regulars' that insist in something called "portability". Portability for them means the least common denominator. Write your code...
7
by: seven.reeds | last post by:
Hi, I have a caontainer div that is 80% of the width of my display and 40em high. It will hold from 2 to 10 columns of data and will almost always have more than 40ems of lines... so it will...
1
Coldfire
by: Coldfire | last post by:
Hello I need a HTML script for Emailing the link, with description, of my site to any email address for-example in the case of "Share this Page with Friends". plz help
2
by: JohnQ | last post by:
Yeah, I'm a lil burnt out and need to go elsewhere. I'll go do that. I know how bad it gets when I mix livelihood.. no, I didn't mean that! I was harkening back to when I worked as a wage slave and...
84
by: aarklon | last post by:
Hi all, I found an interesting article here:- http://en.wikipedia.org/wiki/Criticism_of_the_C_programming_language well what do you guys think of this article....??? Is it constructive...
1
FLEB
by: FLEB | last post by:
I'm working on a PHP/MySQL site with social networking and "message blast" functionality, and I'm not sure what the best method to represent multiple levels of interpersonal relationships in the...
0
by: delhi institute of management & services | last post by:
Delhi Institute of Management & Services Dear friends, We are extremely happy to welcome you to the world of Management... We are in the process of preparing some 5 minutes revision Q & A type...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.