allObjects returns an array, but object values are nil

3 views
Skip to first unread message

Vramin

unread,
Apr 20, 2009, 6:53:04 AM4/20/09
to sqlitepersistentobjects-user
I must be missing something obvious. If I do something like this,
where ListMaster is my SQLPO:

displayList = [[ListMaster class] allObjects];

I get an appropriate number of array elements back, of the correct
type, but only the PK actually contains a value. The rest of the
object properties are nil.

I thought that they should come back fully populated, and I've had no
luck finding a method to get them to fill themselves up in case I'm
running into some lazy loading situation where it waits to go back to
the database until the value is actually needed.

Am I just misunderstanding how this is supposed to work? I see that
the query goes in as "select pk,* from list_master", so only the named
column is appearing in the resultant array as anything more than a
placeholder. Am I supposed to do subsequent findByPk calls to flesh
out the objects and just use allObjects to get a reference list?

Hmm... even if I used findByPk the only property populated in the
resultant object is pk. What am I missing?

Here's what my ListMaster object looks like:

@interface ListMaster : SQLitePersistentObject {

NSString * name;
NSNumber * auto_flag;
NSDate * last_gen_date;
NSString * recurrence_rule;
NSNumber * gen_time;
}
@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) NSNumber * auto_flag;
@property (nonatomic, retain) NSDate * last_gen_date;
@property (nonatomic, retain) NSString * recurrence_rule;
@property (nonatomic, retain) NSNumber * gen_time;

Adam Jack

unread,
Apr 20, 2009, 8:49:03 AM4/20/09
to sqlitepersiste...@googlegroups.com
I think it ought give you the full loaded objects.

Have you had any luck getting any of the object loads to work? I vaguely recall a problem similar to this when I had _ in variable names. I think SQLPO prefers autoFlag to auto_flag and fails silently (not sure why) if variables contain _. (Do you see double underscore in column names in the tables when .dump'ed with sqlite3? I think the code to go from column to variable trips on your _.)

I merely renamed my variables and moved on.

Just a guess, but maybe worth a quick try.

regards

Adam

Marty Picco

unread,
Apr 20, 2009, 10:29:46 AM4/20/09
to sqlitepersiste...@googlegroups.com, sqlitepersiste...@googlegroups.com
I spent several hours tracking this down yesterday. I had exactly the same problem.  You probably have a property name that starts with a capital. This is a bug. Check the issues list on google code. 

Marty

Ps.Remember to delete your app and reinstall when you change the db schema. 

Sent from my mobile. 

Ken

unread,
Apr 20, 2009, 11:14:01 AM4/20/09
to sqlitepersistentobjects-user
Use the following: displayList = [ListMaster allObjects];

What you showed in your code snippet took ListMaster and got the
instance of Class that represents it, and called allObjects on the
Class type. This isn't what you want. You want all objects from
ListMaster.

Ken

Vramin

unread,
Apr 20, 2009, 11:18:21 AM4/20/09
to sqlitepersistentobjects-user
Sir, you are a genius.

I had seen this mentioned in a couple of other threads, but had not
associated it with the problem that I was having... as it turns out,
changing these variable names was the fix. I'm glad I stopped banging
my head against the wall and asked here on the group.

Thank you so much for getting me off the dime!

Vramin

unread,
Apr 20, 2009, 11:24:31 AM4/20/09
to sqlitepersistentobjects-user
Per Adam's suggestion, renaming the variables did the trick. My table
was already structured with underscores in it, so I didn't have to
rebuild my schema or anything, I just needed to let the framework do
its naming magic and get out of the way.

Thank you for the tip about the class keyword. I had tried the syntax
with and without the class keyword and, now that the naming is
corrected, either syntax works (I've run it both ways). I'll stick
with [ListMaster allObjects] because it's cleaner. I had found on
example online where they used [[ListMaster class] allObjects]. I
wasn't clear on the distinction, but I was willing to try anything at
that point.
Reply all
Reply to author
Forward
0 new messages