【问题标题】:Query PFUser currentUser for a custom field查询 PFUser currentUser 以获取自定义字段
【发布时间】:2015-06-13 15:01:14
【问题描述】:

我正在使用解析框架,想知道如何查询位于 PFUser 表中的列。

这里是一些示例代码:

//Adds athlete_id column to roster table    
PFObject *roster = [PFObject objectWithClassName:@"Roster"];
roster[@"athlete_id"] = answer;
[roster save];

//Adds the rosters objectId to an array (athlete_id) in the User table. 
PFUser *currentUser = [PFUser currentUser];
[currentUser addObject:roster.objectId forKey:@"athlete_id"];
[currentUser saveInBackground];

通过上面的代码,最终在名为“athlete_id”的列中的 User 类中获得了一个 objectsID 数组。

我在从 User 类中检索这个数组时遇到了问题。这是我尝试从用户那里获取数组的方式:

FQuery *query = [PFUser query];;
    [query whereKey:@"username" equalTo:[PFUser currentUser].username];
    [query whereKeyExists:@"athelete_id"];
    [query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
        if (!error) {

            NSLog(@"athlete %@", objects);

        } else {

            NSLog(@"Error: %@ %@", error, [error userInfo]);

        }
    }];

我想为当前用户获取包含在 player_id 列中的数组,但在此查询中对象数组为空。

【问题讨论】:

    标签: ios objective-c parse-platform


    【解决方案1】:

    您不需要查询。

    这样做:

    NSString *athleteId = [[PFUser currentUser] objectForKey:@"athelete_id"];
    
    NSLog(@"The athlete id is %@", athleteId);
    

    【讨论】:

    • 感谢您的快速回复。这似乎是一种更简单的方法,但 playerId 的值现在为空。 “athlete_id”列中的内容是名册表中objectsId的数组。
    • @klmitchell2 您想要每个用户的对象 ID 还是只需要当前用户的?运动员 ID 列中有数据吗?
    • 请注意,对于添加到 USER 类的任何新字段,您需要注销并重新登录才能在您的应用中看到它们。
    • @GrandSteph 这也是我的问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-16
    • 2015-03-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多