If the author attribute is stored in JSON (anything not serializable by the database is stored that way), it will be serialized as the following hash:
{
'__metadata__' => {
'class' => 'Person',
'id' => 'insert some kind of UUID here'
}
}
Using Postgres' JSON operators, we can join this Book table with the Person table on that id:
SELECT *
FROM "Book"
INNER JOIN "Person"
ON ("Book"."author"->'__metadata__'->>'id')::uuid = "Person"."id"
WHERE "Person"."name" = 'Foo'
The downside is that we can't use the fact that the Person class is specified in the serialized form. We need to know the type (or types) of the author attribute before we send off the query, which isn't yet possible because we need the core perpetuity gem to pass in the attributes to the query. There isn't anything we can do on this end until that happens, but I wanted to open this issue to remind myself about it.
Given the following query:
If the
author
attribute is stored in JSON (anything not serializable by the database is stored that way), it will be serialized as the following hash:Using Postgres' JSON operators, we can join this
Book
table with thePerson
table on that id:The downside is that we can't use the fact that the
Person
class is specified in the serialized form. We need to know the type (or types) of theauthor
attribute before we send off the query, which isn't yet possible because we need the coreperpetuity
gem to pass in the attributes to the query. There isn't anything we can do on this end until that happens, but I wanted to open this issue to remind myself about it.