Skip to content
This repository has been archived by the owner on Jan 13, 2021. It is now read-only.

Relationships between "sections" #199

Open
Saunved opened this issue Oct 24, 2020 · 0 comments
Open

Relationships between "sections" #199

Saunved opened this issue Oct 24, 2020 · 0 comments

Comments

@Saunved
Copy link
Contributor

Saunved commented Oct 24, 2020

Is your feature request related to a problem? Please describe.
One of the issues I am currently facing is managing relationships between data. E.g. Suppose I have a many-1 course-teacher mapping. It would be nice to get the teacher information along with a course and vice-versa.

Describe the solution you'd like
Section tags could get a relation key-value pair, such as this:

<!-- One course can have one teacher -->
{{#section courses multiple=true relation=teachers mapping=one key=email}} 
    <h2>{{name}}</h2>
    <p>{{description}}/p>
    <p>{{price}}</p>
{{/section}}

And the corresponding teacher section will get its mapping such as:

<!-- One teacher can have many courses -->
{{#section teachers multiple=true relation=courses mapping=many key=slug}} 
    <h2>{{name}}</h2>
    <p>{{description}}</p>
    <p>{{email}}</p>
{{/section}}

The "mapping" key will have one of two values, "one" or "many", with the default value being "one".
The "key" key allows us to define the respective Foreign Keys.

To access relationships in the respective sections, this is what we would have to write:

{{#section teachers multiple=true relation=courses mapping=many key=slug}} 
    <h2>{{name}}</h2>
    <p>{{description}}</p>
    <p>{{email}}</p>

    <h2>Courses by this teacher</h2>
    {{#loop courses}}
        <h3>{{name}}</h3>
    {{/loop}}
{{/section}}

Notice the new loop tag.

For one-one mappings, we won't need to use the loop tag. We can simply do this:

<!-- One course can have one teacher -->
{{#section courses multiple=true relation=teachers mapping=one key=email}} 
    <h2>{{name}}</h2>
    <p>{{description}}/p>
    <p>{{price}}</p>
<!-- The teacher mapped to this course will be available with a dot notation as the "relation" key's value -->
    <p>{{teachers.name}}</p>
{{/section}}

For multiple relations, the relation key could be comma separated. The position of the parameters must be the same.
In the example below we can see the following relations:
x course(s) - 1 teacher (foreign key is email)
x course(s) - many students (foreign key is email)
x course(s) - one moderator (foreign key is username)

{{#section courses multiple=true relation=teachers,students,moderators mapping=one,many,one key=email,email,username}} 

On the CMS UI side, the "key" will be injected automatically in the relevant table.
The Section could also have an indicator that shows the relationships this section has with other sections.
i.e. Teachers and Courses will get a "email" key if it isn't supplied in the UI since it is a requirement for the mapping
and both Courses and Teachers will get a "slug" key even if it isn't referred to in the UI since it is a requirement for the mapping

Describe alternatives you've considered
I haven't found any alternatives yet. I shall add them here if I have any other ideas.

Additional context
I know that Vapid is intentionally simple and the idea of adding relationships in can make things a little complicated, but I would love to have a discussion about the idea and see where it can go :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant