Virtual attributes
I have several manual relationships that are populated using recursive queries, and I would like to be able to expose the depth and path fetched by those queries on the related resource. When not in the context of the relationship, these attributes don't make sense, and thus needn't be queried nor have columns in the table.
Is there a way to create "placeholder" attributes that will be valid in the resource struct, for purposes of manual population? Right now, I'm putting them in
__metadata__
, which hopefully is safe.6 Replies
Metadata is the place for that kind of thing 🙂
Thanks mate.
Think this is related to https://discord.com/channels/711271361523351632/1019647368196534283/threads/1091304226040324117 from yesterday?
Discord
Discord - A New Way to Chat with Friends & Communities
Discord is the easiest way to communicate over voice, video, and text. Chat, hang out, and stay close with your friends and communities.
For the case of queried attributes, being able to specify something like:
Populating these in
__metadata__
or another safe place purpose-built for this?Could you tell me a bit more about what you're doing?
I think he was trying to have a
role
attribute on his many_to_many
join resource teachers_courses
, specifying whether that teacher was primary
, secondary
, etc.
The topic overall was interesting because it's not uncommon to want to have data on graph edges.
The way I've been handling this is to transform many_to_many
into has_many
with the join resource and use preparations
if it's the case that I always care about the related resource and not just the edge metadata.