-
I want to ask if it's possible to get the context object of the the currently generated instance. Here is my situation in a piece of code below: List<Airport> airports = Instancio.ofList(Airport.class)
.size(5)
.generate(field(Airport::getCode), gen -> gen.oneOf(destinations))
.supply(field(Airport::getProvider), gen -> gen.oneOf(savedProviders))
//the ctx field throws error showing it doesn't exist as far as Instancio's supply() is concerned
.supply(Select.field(Airport::getCountry), (gen, ctx) -> ctx.get(Select.field(Airport::getCode)))
.create(); My goal for this is: I want to set the value of |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
You can assign the generated value of one field to another field using the List<Airport> airports = Instancio.ofList(Airport.class)
//...snip
.assign(Assign.valueOf(field(Airport::getCode)).to(field(Airport::getCountry)))
.create(); Please see the docs for more examples: https://www.instancio.org/user-guide/#using-assign |
Beta Was this translation helpful? Give feedback.
You can assign the generated value of one field to another field using the
assign()
method:Please see the docs for more examples: https://www.instancio.org/user-guide/#using-assign