Created
October 7, 2020 18:27
-
-
Save hpneo/4f749d2cff2968728f94d13041ab0c1d to your computer and use it in GitHub Desktop.
Many to Many in Overpass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const resources = defineResources(({ resource, belongsTo, hasMany }) => { | |
| resource("users", () => hasMany("savedProperties")); | |
| resource("properties"); // Could be `resource("properties", () => hasMany("savedProperties"));` | |
| resource("savedProperties", () => belongsTo("property")); | |
| }); | |
| return ( | |
| <OverpassProvider | |
| api={{ | |
| apiHost: location.host, | |
| apiPrefix: "/api", | |
| additionalHeaders: { | |
| "X-CSRF-Token": csrfTag?.content, | |
| }, | |
| }} | |
| resources={resources} | |
| /> | |
| ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const fetchSavedPropertiesCollection = useFetchCollection( | |
| "savedProperties", | |
| { | |
| include: ["property"] | |
| } | |
| ); | |
| const savedProperties = useNestedCollection( | |
| "savedProperties", | |
| { | |
| property: {} | |
| } | |
| ); | |
| const properties = savedProperties | |
| .filter((savedProperty) => savedProperty.property) | |
| .map((savedProperty) => savedProperty.property); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class API::PropertyResource < JSONAPI::Resource | |
| has_many :saved_properties | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class API::SavedPropertyResource < JSONAPI::Resource | |
| has_one :user | |
| has_one :property | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class API::UserResource < JSONAPI::Resource | |
| has_many :saved_properties | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment