@kaspernj/api-maker 1.0.328 → 1.0.329
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -11,4 +11,5 @@ export default class ApiMakerBaseModelReflection {
|
|
|
11
11
|
macro = () => digg(this, "reflectionData", "macro")
|
|
12
12
|
modelClass = () => modelClassRequire(inflection.singularize(inflection.camelize(digg(this, "reflectionData", "resource_name"))))
|
|
13
13
|
name = () => inflection.camelize(digg(this, "reflectionData", "name"), true)
|
|
14
|
+
through = () => digg(this, "reflectionData", "through")
|
|
14
15
|
}
|
|
@@ -43,21 +43,37 @@ const ApiMakerSuperAdminShowPage = ({modelClass}) => {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
for (const reflection of modelClass.reflections()) {
|
|
46
|
-
if (reflection.macro()
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
if (
|
|
46
|
+
if (reflection.macro() == "belongs_to") {
|
|
47
|
+
const reflectionModelClass = reflection.modelClass()
|
|
48
|
+
const reflectionModelClassName = reflectionModelClass.modelClassData().name
|
|
49
|
+
const reflectionModelClassAttributes = reflectionModelClass.attributes()
|
|
50
|
+
const nameAttribute = reflectionModelClassAttributes.find((attribute) => attribute.name() == "name")
|
|
51
|
+
|
|
52
|
+
preload.push(inflection.underscore(reflection.name()))
|
|
53
|
+
|
|
54
|
+
if (!(reflectionModelClassName in select)) select[reflectionModelClassName] = []
|
|
55
|
+
if (!select[reflectionModelClassName].includes("id")) select[reflectionModelClassName].push("id")
|
|
56
|
+
if (nameAttribute && !select[reflectionModelClassName].includes("name")) select[reflectionModelClassName].push("name")
|
|
57
|
+
|
|
58
|
+
// The foreign key is needed to look up any belongs-to-relationships
|
|
59
|
+
if (!modelClassSelect.includes(reflection.foreignKey())) modelClassSelect.push(reflection.foreignKey())
|
|
60
|
+
} else if (reflection.macro() == "has_one") {
|
|
61
|
+
const reflectionModelClass = reflection.modelClass()
|
|
62
|
+
const reflectionModelClassName = reflectionModelClass.modelClassData().name
|
|
63
|
+
const reflectionModelClassAttributes = reflectionModelClass.attributes()
|
|
64
|
+
const nameAttribute = reflectionModelClassAttributes.find((attribute) => attribute.name() == "name")
|
|
65
|
+
|
|
66
|
+
preload.push(inflection.underscore(reflection.name()))
|
|
67
|
+
|
|
68
|
+
if (!(reflectionModelClassName in select)) select[reflectionModelClassName] = []
|
|
69
|
+
if (!select[reflectionModelClassName].includes("id")) select[reflectionModelClassName].push("id")
|
|
70
|
+
if (nameAttribute && !select[reflectionModelClassName].includes("name")) select[reflectionModelClassName].push("name")
|
|
71
|
+
|
|
72
|
+
// The foreign key is needed to look up any has-one-relationships
|
|
73
|
+
if (!modelClassSelect.includes(reflection.foreignKey()) && !select[reflectionModelClassName].includes(reflection.foreignKey()) && !reflection.through()) {
|
|
74
|
+
select[reflectionModelClassName].push(reflection.foreignKey())
|
|
75
|
+
}
|
|
76
|
+
}
|
|
61
77
|
}
|
|
62
78
|
|
|
63
79
|
const useModelResult = useModel(modelClass, {
|
|
@@ -79,7 +95,7 @@ const ApiMakerSuperAdminShowPage = ({modelClass}) => {
|
|
|
79
95
|
{attributes && model && attributes.map((attribute) =>
|
|
80
96
|
<AttributePresenter attribute={attribute} key={attribute.attribute || attribute} modelArgs={modelArgs} model={model} />
|
|
81
97
|
)}
|
|
82
|
-
{model && modelClass.reflections().filter((reflection) => reflection.macro() == "belongs_to").map((reflection) =>
|
|
98
|
+
{model && modelClass.reflections().filter((reflection) => reflection.macro() == "belongs_to" || reflection.macro() == "has_one").map((reflection) =>
|
|
83
99
|
<BelongsToAttributeRow key={reflection.name()} model={model} modelClass={modelClass} reflection={reflection} />
|
|
84
100
|
)}
|
|
85
101
|
{model && extraContent && extraContent(modelArgs)}
|