pardom-zz / ActiveAndroid

Active record style SQLite persistence for Android
http://www.activeandroid.com
4.7k stars 1.03k forks source link

JSON object array #281

Open lewisevans opened 10 years ago

lewisevans commented 10 years ago

Im new to AA and I need some newb guidance!

I have a JSON Pod object:

    {
      "_id": "pod-UQ5et2YV4ixgFz46FAsCuX",
      "content": [
        {
          "_id": "content-83b83a76-7d86-4dd0-b2ce-fb2ecb5a0053"
        }
      ],
      "updated": "2014-10-10T15:37:47"
    }

I have a java class representation of the said Pod object:

@Table(name = "Pod")
public class Pod extends Model
    @Column(name = BaseModel.Columns.ItemId)
    private String _id;

    @Column(name = Columns.content)
    private ArrayList<Content> content; //

    @Column(name = Columns.updated)
    private Date updated; //

   //code here//
}

Here is the Content object:

@Table(name = "Content")
public class Content extends Model {
    @Column(name = BaseModel.Columns.ItemId)
    private String _id;

    @Column(name = Columns.content)
    private String content;

   //code here//
}

Now the content array has Content items in it that can belong to many different Pods.

How would I build these relationships?

I've tried storing the content array as an array of string by parsing the array and storing a contentStrings array but I thought there must be a better way to reference the Content objects that are in my DB?

jvanwinden commented 9 years ago

What do you mean by 'the content array'? Do you mean an array all the possible contents, or an array of which Contents belong to an Item?