liquid_feedback_frontend
view model/contact.lua @ 1361:324e01ab8ecf
Show sequential number as read only
| author | bsw | 
|---|---|
| date | Mon Aug 06 14:00:45 2018 +0200 (2018-08-06) | 
| parents | 701a5cf6b067 | 
| children | 
 line source
     1 Contact = mondelefant.new_class()
     2 Contact.table = 'contact'
     3 Contact.primary_key = { "member_id", "other_member_id" }
     5 Contact:add_reference{
     6   mode          = 'm1',
     7   to            = "Member",
     8   this_key      = 'member_id',
     9   that_key      = 'id',
    10   ref           = 'member',
    11 }
    13 Contact:add_reference{
    14   mode          = 'm1',
    15   to            = "Member",
    16   this_key      = 'other_member_id',
    17   that_key      = 'id',
    18   ref           = 'other_member',
    19 }
    22 function Contact:by_pk(member_id, other_member_id)
    23   return self:new_selector()
    24     :add_where{ "member_id = ?", member_id }
    25     :add_where{ "other_member_id = ?", other_member_id }
    26     :optional_object_mode()
    27     :exec()
    28 end
    30 function Contact:build_selector(args)
    31   local selector = Contact:new_selector()
    32   selector:join("member", nil, "member.id = contact.other_member_id")
    33   if args.member_id then
    34     selector:add_where{ "member_id = ?", args.member_id }
    35   end
    36   if args.public ~= nil then
    37     selector:add_where{ "public = ?", args.public }
    38   end
    39   if args.order then
    40     if args.order == "name" then
    41       selector:add_order_by("member.name")
    42     else
    43       error("invalid order")
    44     end
    45   end
    46   return selector
    47 end
