Closed inawlaljar closed 9 years ago
Sorry, I'm not sure if I understand what you're asking. The code you posted will generate:
public class Organization extends TableModel {
...
}
Do you then want to create a subclass of Organization? What specifically are you hoping to accomplish? You can of course subclass the generated model classes but needing to do so is an uncommon use case -- there may be a better approach depending on what you're actually trying to do.
Thanks. While reading the data (json formatted) from the server using retrofit, I am converting the json into objects for which I have simple POJOs which are quite similar to Models required for Squidb. As you can imagine then I have to convert them in to Squidb models to persist them in the local db. Now, any change I bring in I have to modify both the classes. I was thinking of deriving one from another ... that will reduce the potential errors
For e.g. public class OrganizationResponse extends Organizations { } OR
public class OrganizationSpec extends OrganizationResponse { }
I see. There are several considerations here:
The first thing to note is that squidb model specs are not really meant to be used as POJOs -- they're just defined that way as a shorthand for a table schema. They're processed by the code generator and translated into entirely different objects, and these generated classes are the ones you actually work with when reading/writing the database. No matter what, you will need to define some kind of logic for mapping your JSON to the generated squidb models in order to persist them.
That being said, there are options, and you can pick whatever approach seems best to you:
@Ignore
, and do something similar for any database columns that didn't correspond to a JSON field. Again though, you would still need to define logic for mapping your POJO to the generated squidb model.Personally I would probably go with option 1 much of the time, but I don't know all the details of your use case and you may very well have different needs (e.g., maybe you're using an API that already defines those POJOs and precludes that option).
For information on code generation plugins, see this wiki page.
If you have more questions or want to provide any more specific details, happy to continue helping or offering advice! I hope that gives you some useful things to think about though.
I'm going to close this issue as there hasn't been any activity on it in a while, but feel free to reopen if you have any more specific questions.
Please suggest whether it is possible to extend the model class.
i.e. for humour
@TableModelSpec(className = "Organization", tableName = "organizations") public class OrganizationSpec { }