librelist archives

« back to archive

getById函数无法查询

getById函数无法查询

From:
连路朋
Date:
2011-08-11 @ 13:13
redis 情况
redis 127.0.0.1:6379[15]> keys *
 1) "MUser:5"
 2) "MUser:__index"
 3) "MUser:6"
 4) "MUser:7"
 5) "MUser:8"
 6) "MUser:9"
 7) "MUser:__counter"
 8) "MUser:10"
 9) "MUser:11"
10) "MUser:12"
11) "MUser:13"
12) "MUser:14"
13) "Session:APP-fd7c7789be2e7bdae4a0287506e79b52"
14) "Session:APP-6d21e8ffa86e6c0d718e2c4ca913bd67"
15) "MUser:1"
16) "MUser:2"
17) "MUser:3"
18) "MUser:4"
redis 127.0.0.1:6379[15]> type MUser:__index
zset
redis 127.0.0.1:6379[15]> type MUser:__counter
string
redis 127.0.0.1:6379[15]> hgetall MUser:1
1) "id"
2) "1"
3) "name"
4) "mg"
5) "password"
6) "lead"
7) "username"
8) "mg"
redis 127.0.0.1:6379[15]>
相应的model代码如下

module(..., package.seeall)
        2
        3 local User = require 'bamboo.models.user'
        4
        5 local MUser = User:extend {
        6     __tag = 'Bamboo.Model.User.MUser';
        7     __name = 'MUser';
        8     __desc = 'Spacial ZDUser definition';
        9     __fields = {
       10
       11         ['username'] = {},
       12         ['password'] = {},
       13     };
       14
       15     init = function (self, t)
       16         if not t then return self end
       17         self.username = t.username
       18         self.password = t.password
       19         return self
       20     end;
查询语句如下
local function get(web,req)
       12     local params = Form:parse(req)
       13     --ptable(params);
       14     local muser = MUser(params);
       15     ptable(muser);
       16     muser:save();
       17     local t2 =MUser:getById(1);
       18     print(type(t2));
       19     if(t2)
       20     then
       21     ptable(table2);
       22     else
       23     print("fuck");
       24     end
输出结果红色部分:nil

-- 
by lianlupeng.

Re: [bamboo] getById函数无法查询

From:
道哥
Date:
2011-08-18 @ 08:15
已解决,提交至serious0分支。

在 2011-08-11 21:13:41,"连路朋" <lianlupeng@gmail.com> 写道:
redis 情况
redis 127.0.0.1:6379[15]> keys *
 1) "MUser:5"
 2) "MUser:__index"
 3) "MUser:6"
 4) "MUser:7"
 5) "MUser:8"
 6) "MUser:9"
 7) "MUser:__counter"
 8) "MUser:10"
 9) "MUser:11"
10) "MUser:12"
11) "MUser:13"
12) "MUser:14"
13) "Session:APP-fd7c7789be2e7bdae4a0287506e79b52"
14) "Session:APP-6d21e8ffa86e6c0d718e2c4ca913bd67"
15) "MUser:1"
16) "MUser:2"
17) "MUser:3"
18) "MUser:4"
redis 127.0.0.1:6379[15]> type MUser:__index
zset
redis 127.0.0.1:6379[15]> type MUser:__counter
string
redis 127.0.0.1:6379[15]> hgetall MUser:1
1) "id"
2) "1"
3) "name"
4) "mg"
5) "password"
6) "lead"
7) "username"
8) "mg"
redis 127.0.0.1:6379[15]>
相应的model代码如下

module(..., package.seeall)
        2
        3 local User = require 'bamboo.models.user'
        4
        5 local MUser = User:extend {
        6     __tag = 'Bamboo.Model.User.MUser';
        7     __name = 'MUser';
        8     __desc = 'Spacial ZDUser definition';
        9     __fields = {
       10
       11         ['username'] = {},
       12         ['password'] = {},
       13     }; 
       14
       15     init = function (self, t)
       16         if not t then return self end
       17         self.username = t.username
       18         self.password = t.password
       19         return self
       20     end;
查询语句如下
local function get(web,req)
       12     local params = Form:parse(req)
       13     --ptable(params);
       14     local muser = MUser(params);
       15     ptable(muser);
       16     muser:save();
       17     local t2 =MUser:getById(1);
       18     print(type(t2));
       19     if(t2)
       20     then
       21     ptable(table2);
       22     else
       23     print("fuck");
       24     end
输出结果红色部分:nil

--
by lianlupeng.