I have defined a model “house” and a model “room” where a house hasMany room. Forest schema update then generated the following:
House.hasMany(models.room, {
foreignKey: {
name: 'houseIdKey',
field: 'house_id'
},
as: 'houseRooms'
})
When I now use the new forest agent and create the typings.ts file, in the schema for house I only see keys in the nested
object that are belongsTo
, hasOne
, but I don’t see the relations that are hasMany
. Why are these not generated?
I tried adding it manually:
import { CollectionCustomizer } from '@forestadmin/agent'
import { Schema } from './autogenerated'
export default (transactions: CollectionCustomizer<Schema, 'house'>) =>
transactions.addOneToManyRelation('houseRooms', 'room', { foreignKey: 'house_id' })
A question that arises here seeing the code: How do I add the name
(in this case houseIdKey) of the foreign key in the new model, if the old code somewhere used a custom name?
And finally, I used the types like this, but I guess it should be imported differently for the customizations and everything to work?
import { HouseRecord } from '../typings.ts
function getRooms( house: HouseRecord ): Array<Room> {
// ....
}
So questions:
- How to get the hasMany relations in my generated types?
- How to migrate the name of the foreign keys in relations?
- How to properly import the types in my .ts files?
Your support is highly appreciated, thank you!
Best
Markus