How to fill a ListProperty?

3 views
Skip to first unread message

pgio

unread,
Jul 19, 2010, 11:36:02 PM7/19/10
to appenginejs
I'm making progress with AppengineJS. I've got a model fully defined,
but I'm having problems with ListProperties. What's the proper method
to fill them? .push() is what I've been trying, but it doesn't work on
a null '' result. Is there something in particular I should be storing
in the ListProperty when the object that owns it is created, to avoid
this problem? Or am I simply using the wrong method?

Pete

George Moschovitis

unread,
Jul 20, 2010, 12:44:46 AM7/20/10
to appen...@googlegroups.com
try:

 var Message = exports.Message = db.Model('Message',{
  ..
  tags: new db.ListProperty()
  ...

var m = new Message({
  ..
  tags: ["hello", "world"]
  ..
});

regards,
-g.
--
http://www.gmosx.com/blog
http://www.appenginejs.org

pgio

unread,
Jul 20, 2010, 3:18:45 PM7/20/10
to appenginejs
It seems that I must pass in a dummy value to the list when it is
created, like
var m = new Message({
...
comments = ["none"]
...
});

then .push() works if you're pushing a string. But the property is
defined as

var Message = exports.Message = db.Model('Message',{
...
comments: new db.ListProperty(Comment)
...
});

and when I try to pass in a Comment object I get:

JavaException: java.lang.IllegalArgumentException: comments:
org.mozilla.javascript.NativeObject is not a supported property type.
(google/appengine/ext/db/model.js#245)

With my CustomUser object, which has a .friendlist of CustomUser
objects, I had to pass in the .userid for the CustomUser, and the
userids are stored in the list, since passing a CustomUser object
produced the same Java exception. Perhaps I should create a similar
property for my Comment object?

Pete

pgio

unread,
Jul 20, 2010, 7:12:24 PM7/20/10
to appenginejs
Just found out that the empty list [""] works for an initial value as
well; I thought it would evaluate as equal to null but apparently not.
Guess it makes sense.

Pete



Frederick Polgardy

unread,
Jul 20, 2010, 8:51:39 PM7/20/10
to appen...@googlegroups.com
That's not the empty list. That's a list of one element: the empty string. Why wouldn't [] work?

--
Science answers questions; philosophy questions answers.

pgio

unread,
Jul 22, 2010, 1:07:20 PM7/22/10
to appenginejs
It was returning an error -- something like "can't call method push of
object null."
Reply all
Reply to author
Forward
0 new messages