The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Add test to prove that #35842 has been fixed (#70080)
metamben486a6fc8261a
diff --git a/test/metabase/queries/models/card_test.clj b/test/metabase/queries/models/card_test.cljindex 33c903763c4..7bb6d42d104 100644--- a/test/metabase/queries/models/card_test.clj+++ b/test/metabase/queries/models/card_test.clj@@ -1365,6 +1365,42 @@(finally(t2/delete! :model/Card (:id card))))))))+(deftest create-native-model-external-remap-query-test+ (testing "External remapping (FK) should work when querying through a native SQL model (#35842)"+ (mt/with-temp [:model/Dimension _ {:field_id (mt/id :orders :user_id)+ :name "User ID"+ :human_readable_field_id (mt/id :people :name)+ :type :external}]+ (mt/with-current-user (mt/user->id :crowberto)+ (mt/with-model-cleanup [:model/Card]+ (let [metadata (qp.preprocess/query->expected-cols (mt/mbql-query orders))+ card (card/create-card! {:database_id (mt/id)+ :display :table+ :visualization_settings {}+ :type :model+ :name "Native Orders Model for external remap test"+ :dataset_query (mt/native-query {:query "SELECT * FROM ORDERS"})+ :result_metadata metadata}+ @api/*current-user*)+ mp (mt/metadata-provider)+ model-query (-> (lib/query mp (lib.metadata/card mp (:id card)))+ (lib/aggregate (lib/count))+ (notebook-helpers/add-breakout "User ID")+ (lib/limit 5))+ result (mt/user-http-request :crowberto :post 202 "dataset" model-query)+ cols (get-in result [:data :cols])+ remap-col (first (filter :remapped_from cols))+ user-col (first (filter #(= (:name %) (:remapped_from remap-col)) cols))]+ (testing "remap column exists with :remapped_from pointing to original column"+ (is (some? remap-col))+ (is (= (:name user-col) (:remapped_from remap-col))))+ (testing "original column has :remapped_to pointing to remap column"+ (is (= (:name remap-col) (:remapped_to user-col))))+ (testing "result rows contain remapped user names"+ (let [col-names (mapv :name cols)+ remap-idx (.indexOf ^java.util.List col-names (:name remap-col))]+ (is (every? string? (map #(nth % remap-idx) (get-in result [:data :rows]))))))))))))+(deftest create-model-internal-remap-query-test(testing "Internal remapping (custom values) should work when querying through a model (#57978)"(mt/with-column-remappings [orders.quantity {0 "Zero" 1 "A" 2 "B" 3 "C" 4 "D"}]