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
ZachDaniel
ZachDaniel3y ago
Metadata is the place for that kind of thing 🙂
\ ឵឵឵
\ ឵឵឵OP3y ago
Thanks mate.
\ ឵឵឵
\ ឵឵឵OP3y ago
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.
\ ឵឵឵
\ ឵឵឵OP3y ago
For the case of queried attributes, being able to specify something like:
relationships do
many_to_many :teacher, App.Teacher do
join_attributes [:role]
end
end
relationships do
many_to_many :teacher, App.Teacher do
join_attributes [:role]
end
end
Populating these in __metadata__ or another safe place purpose-built for this?
ZachDaniel
ZachDaniel3y ago
Could you tell me a bit more about what you're doing?
\ ឵឵឵
\ ឵឵឵OP3y ago
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.

Did you find this page helpful?