You are here: ActiveRecord and Foreign Keys « PHP Programming Language « IT news, forums, messages
ActiveRecord and Foreign Keys

Posted by Carl Vondrick on 07/25/06 03:36

Hi everyone,
I am having trouble wrapping my mind around the ActiveRecord pattern and
foreign keys.

I understand that for each table, there should be a class, and each row
is is effectively an instance.

But, my problem arises when I look at foreign keys and advanced
relationships. For basic foreign keys, I can just automatically
reference to the object. Example:

Table: invoice
id, notes

Table: items
id, cost, invoice_id

When working with an instance with items, I can easily load a new object
called "invoice."

But, what if I am already working with invoice, and I want to load
items? I can't think of any way to abstractly relate the two.

Also, what if I want to two things that are both a "has many"
relationship? For example, if I take users that can have multiple
qualities, I would need three tables: one for users, one for the
qualities, and one to link.

Table: users
id, username

Table: link
id, user_id, quality_id

table: qualities
id, quality_name

How does ActiveRecord adapt to this? Any insight that you have or
suggestions are appreciated! I can't think of an elegant solution.

Carl

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация