Use multiple @Observable inside each other using @Enviroment

Hello I'm trying the new Observation in SwiftUI, I created 2 classes using the new @Observable wrapper like this:

@Observable
class CategoriesViewModel {
    var categories: [Category] = []
}
@Observable
class NotesViewModel {
    var notes: [Note] = []
}

and I'm using them in the views like this:

@Environment(CategoriesViewModel.self) var categoriesViewModel

The question is: what if I want to use an observable inside another observable ? for example, I want to use the categories inside the NotesViewModel, I tried the @State instead of @Enviroment but it's not a global across all classes, so I want to use it as an environment variable like what I did in the views, I tried to use it inside the Observable class like this but I got an error below:

@Observable
class NotesViewModel {
    var notes: [Note] = []

    @ObservationIgnored
    @Environment(CategoriesViewModel.self) var categoriesViewModel: CategoriesViewModel


    func foo(){
        /// Thread 1: Fatal error: No Observable object of type CategoriesViewModel found. A View.environmentObject(_:) for CategoriesViewModel may be missing as an ancestor of this view.
        print(categoriesViewModel.categories.count)
    }
}

I have not used the new @Observable stuff yet, but I am pretty sure that @Environment is used in SwiftUI views, not in view models.

What happens if you add the categories view model as a regular property of the NotesViewModel class without any property wrappers?

@Observable
class NotesViewModel {
    var notes: [Note] = []
    var categoriesViewModel: CategoriesViewModel

    func foo(){
        /// Thread 1: Fatal error: No Observable object of type CategoriesViewModel found. A View.environmentObject(_:) for CategoriesViewModel may be missing as an ancestor of this view.
        print(categoriesViewModel.categories.count)
    }
}
Use multiple @Observable inside each other using @Enviroment
 
 
Q