@@ -675,4 +675,61 @@ public function terms_are_found_using_where_relation()
675675 $ this ->assertCount (1 , $ terms );
676676 $ this ->assertEquals (['c ' ], $ terms ->map ->slug ->all ());
677677 }
678+
679+ #[Test]
680+ public function it_ensures_taxonomy_column_is_selected_when_columns_are_specified ()
681+ {
682+ Taxonomy::make ('tags ' )->save ();
683+ Term::make ('a ' )->taxonomy ('tags ' )->data (['title ' => 'Term A ' , 'description ' => 'Description A ' ])->save ();
684+ Term::make ('b ' )->taxonomy ('tags ' )->data (['title ' => 'Term B ' , 'description ' => 'Description B ' ])->save ();
685+
686+ // When specific columns are requested (not including taxonomy), taxonomy should be auto-added
687+ $ terms = Term::query ()->get (['slug ' , 'data ' ]);
688+ $ this ->assertCount (2 , $ terms );
689+ $ this ->assertEquals (['a ' , 'b ' ], $ terms ->map ->slug ()->all ());
690+
691+ // When empty array is passed, should not add taxonomy column
692+ $ terms = Term::query ()->get ([]);
693+ $ this ->assertCount (2 , $ terms );
694+ $ this ->assertEquals (['a ' , 'b ' ], $ terms ->map ->slug ()->all ());
695+
696+ // When * is requested, taxonomy is included automatically
697+ $ terms = Term::query ()->get (['* ' ]);
698+ $ this ->assertCount (2 , $ terms );
699+ $ this ->assertEquals (['a ' , 'b ' ], $ terms ->map ->slug ()->all ());
700+
701+ // When taxonomy is already included, should not be duplicated
702+ $ terms = Term::query ()->get (['slug ' , 'taxonomy ' , 'data ' ]);
703+ $ this ->assertCount (2 , $ terms );
704+ $ this ->assertEquals (['a ' , 'b ' ], $ terms ->map ->slug ()->all ());
705+ }
706+
707+ #[Test]
708+ public function it_ensures_taxonomy_column_is_selected_when_paginating_with_columns ()
709+ {
710+ Taxonomy::make ('tags ' )->save ();
711+ Term::make ('a ' )->taxonomy ('tags ' )->data (['title ' => 'Term A ' ])->save ();
712+ Term::make ('b ' )->taxonomy ('tags ' )->data (['title ' => 'Term B ' ])->save ();
713+ Term::make ('c ' )->taxonomy ('tags ' )->data (['title ' => 'Term C ' ])->save ();
714+
715+ // When specific columns are requested in paginate (not including taxonomy), taxonomy should be auto-added
716+ $ paginated = Term::query ()->paginate (2 , ['slug ' , 'data ' ]);
717+ $ this ->assertCount (2 , $ paginated );
718+ $ this ->assertEquals (['a ' , 'b ' ], $ paginated ->getCollection ()->map ->slug ()->all ());
719+
720+ // When empty array is passed to paginate, should not add taxonomy column
721+ $ paginated = Term::query ()->paginate (2 , []);
722+ $ this ->assertCount (2 , $ paginated );
723+ $ this ->assertEquals (['a ' , 'b ' ], $ paginated ->getCollection ()->map ->slug ()->all ());
724+
725+ // When * is requested in paginate, taxonomy is included automatically
726+ $ paginated = Term::query ()->paginate (2 , ['* ' ]);
727+ $ this ->assertCount (2 , $ paginated );
728+ $ this ->assertEquals (['a ' , 'b ' ], $ paginated ->getCollection ()->map ->slug ()->all ());
729+
730+ // When taxonomy is already included in paginate, should not be duplicated
731+ $ paginated = Term::query ()->paginate (2 , ['slug ' , 'taxonomy ' , 'data ' ]);
732+ $ this ->assertCount (2 , $ paginated );
733+ $ this ->assertEquals (['a ' , 'b ' ], $ paginated ->getCollection ()->map ->slug ()->all ());
734+ }
678735}
0 commit comments