Re: First-class Polymorphic joins?

Поиск
Список
Период
Сортировка
От Adrian Klaver
Тема Re: First-class Polymorphic joins?
Дата
Msg-id 55CD3EA5.8090309@aklaver.com
обсуждение исходный текст
Ответ на First-class Polymorphic joins?  (Guyren Howe <guyren@gmail.com>)
Ответы Re: First-class Polymorphic joins?
Список pgsql-general
On 08/13/2015 05:59 PM, Guyren Howe wrote:

Ccing list

> On Aug 13, 2015, at 17:49 , Adrian Klaver <adrian.klaver@aklaver.com> wrote:
>>
>>> A polymorphic join is where a fk contains not just an id but an indicator of which table it refers to.
>>
>> I am pretty sure it already does that:
>>
>> http://www.postgresql.org/docs/9.4/interactive/sql-createtable.html
>>
>> REFERENCES reftable [ ( refcolumn ) ]
>
> I apologize for not being clearer.
>
> The point is that the fk in different rows can reference different tables. I might want to be able to attach a tag to
aperson or a blog post, say. And then I want to find all the persons and blog posts with a particular tag, in a single
query.

Could you just not turn that around?:

tag
   tag_id
   tag_desc

person
   person_id
   tag_fk references tag

blog
   blog_id
   tag_fk references tag

>
> The simplest implementation is to have a table reference as a first-class value I can store in a field.
>


--
Adrian Klaver
adrian.klaver@aklaver.com


В списке pgsql-general по дате отправления:

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: Foreign Keys as first class citizens at design time?
Следующее
От: Martín Marqués
Дата:
Сообщение: Migrations (was: First-class Polymorphic joins?)