declex icon indicating copy to clipboard operation
declex copied to clipboard

@ModelField annotation

Open smaugho opened this issue 7 years ago • 0 comments

Often it is useful to have references to only one field of a specific model, @ModelField annotation will do this, takins as parameter the Model and the field (which could be omitted), and it takes all the other parameters of @Model annotation. For instance, let's say the object Token it is stored in the preferences, or in the DataBase, and in most of your models what you need it is only the "token" string of this model, so you can do like this:

@ServerModel(...)
public class MyModel {

    @ModelField(model=Token.class)
    String token;    

}

Model field will inject the model similar to @Model, but it passes in fields the name "token", so that only that field be fetched from the interface (DB, Preferences, Server).

This makes the code much more cleaner..

@ModelField is compatible with the Actions $LoadModel and $PutModel (as well as $Populate and $Recollect), but note that in any case, it will be trying to load/put only one field.

smaugho avatar Mar 25 '17 16:03 smaugho