Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
Metabase
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Engineering Digital Service
Metabase
Commits
9a00cf38
Unverified
Commit
9a00cf38
authored
8 years ago
by
Cam Saül
Browse files
Options
Downloads
Patches
Plain Diff
Fix GET /api/database/:id/idfields if DB has no tables
parent
0c65035d
Loading
Loading
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/metabase/api/database.clj
+4
-5
4 additions, 5 deletions
src/metabase/api/database.clj
src/metabase/models/database.clj
+8
-0
8 additions, 0 deletions
src/metabase/models/database.clj
with
12 additions
and
5 deletions
src/metabase/api/database.clj
+
4
−
5
View file @
9a00cf38
(
ns
metabase.api.database
"/api/database endpoints."
(
:require
[
clojure.tools.logging
:as
log
]
(
:require
[
clojure.string
:as
s
]
[
clojure.tools.logging
:as
log
]
[
compojure.core
:refer
[
GET
POST
PUT
DELETE
]]
[
metabase.api.common
:refer
:all
]
(
metabase
[
config
:as
config
]
...
...
@@ -10,7 +11,7 @@
[
sample-data
:as
sample-data
]
[
util
:as
u
])
(
metabase.models
common
[
database
:refer
[
Database
protected-password
]]
[
database
:refer
[
Database
protected-password
]
,
:as
database
]
[
field
:refer
[
Field
]]
[
hydrate
:refer
[
hydrate
]]
[
table
:refer
[
Table
]])))
...
...
@@ -200,9 +201,7 @@
"Get a list of all primary key `Fields` for `Database`."
[
id
]
(
read-check
Database
id
)
(
let
[
table_ids
(
db/select-ids
Table,
:db_id
id,
:active
true
)]
(
sort-by
#
(
:name
(
:table
%
))
(
->
(
db/select
Field,
:table_id
[
:in
table_ids
]
,
:special_type
"id"
)
(
hydrate
:table
)))))
(
sort-by
(
comp
s/lower-case
:name
:table
)
(
hydrate
(
database/pk-fields
{
:id
id
})
:table
)))
(
defendpoint
POST
"/:id/sync"
"Update the metadata for this `Database`."
...
...
This diff is collapsed.
Click to expand it.
src/metabase/models/database.clj
+
8
−
0
View file @
9a00cf38
...
...
@@ -29,6 +29,14 @@
[{
:keys
[
id
]}]
(
db/select
'Table,
:db_id
id,
:active
true,
{
:order-by
[[
:display_name
:asc
]]}))
(
defn
pk-fields
"Return all the primary key `Fields` associated with this DATABASE."
[{
:keys
[
id
]}]
(
let
[
table-ids
(
db/select-ids
'Table,
:db_id
id,
:active
true
)]
(
when
(
seq
table-ids
)
(
db/select
'Field,
:table_id
[
:in
table-ids
]
,
:special_type
"id"
))))
(
u/strict-extend
(
class
Database
)
i/IEntity
(
merge
i/IEntityDefaults
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment