webmcp
diff demo-app/model/medium.lua @ 0:9fdfb27f8e67
Version 1.0.0
author | jbe/bsw |
---|---|
date | Sun Oct 25 12:00:00 2009 +0100 (2009-10-25) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/demo-app/model/medium.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,45 @@ 1.4 +Medium = mondelefant.new_class() 1.5 +Medium.table = 'medium' 1.6 + 1.7 +Medium:add_reference{ 1.8 + mode = 'm1', -- many (m) Medium entries can refer to one (1) MediaType 1.9 + to = "MediaType", -- name of referenced model (quoting avoids auto-loading here) 1.10 + this_key = 'media_type_id', -- own key in medium table 1.11 + that_key = 'id', -- other key in media_type table 1.12 + ref = 'media_type', -- name of reference 1.13 + back_ref = nil, -- not used for m1 relation! 1.14 + default_order = nil -- not used for m1 relation! 1.15 +} 1.16 + 1.17 +Medium:add_reference{ 1.18 + mode = '1m', -- one (1) Medium has many (m) Classifications 1.19 + to = "Classification", -- name of referenced model (quoting avoids auto-loading here) 1.20 + this_key = 'id', -- own key in medium table 1.21 + that_key = 'medium_id', -- other key in classification table 1.22 + ref = 'classifications', -- name of reference 1.23 + back_ref = 'medium', -- each autoloaded classification automatically refers back to the Medium 1.24 + default_order = '"genre_id"' -- order classifications by SQL expression "genre_id" 1.25 +} 1.26 + 1.27 +Medium:add_reference{ 1.28 + mode = 'mm', -- many (m) Media belong to many (m) Genres 1.29 + to = "Genre", -- name of referenced model (quoting avoids auto-loading here) 1.30 + this_key = 'id', -- (primary) key of medium table 1.31 + that_key = 'id', -- (primary) key of genre talbe 1.32 + connected_by_table = 'classification', -- table connecting media with genres 1.33 + connected_by_this_key = 'medium_id', -- key in classification table referencing media 1.34 + connected_by_that_key = 'genre_id', -- key in classification table referencing genres 1.35 + ref = 'genres', -- name of reference 1.36 + back_ref = nil, -- not used for mm relation! 1.37 + default_order = '"genre"."name", "genre"."id"' -- mm references need qualified names in SQL order expression! 1.38 +} 1.39 + 1.40 +Medium:add_reference{ 1.41 + mode = '1m', -- one (1) Medium has many (m) Tracks 1.42 + to = "Track", -- name of referenced model (quoting avoids auto-loading here) 1.43 + this_key = 'id', -- own key in medium table 1.44 + that_key = 'medium_id', -- other key in track table 1.45 + ref = 'tracks', -- name of reference 1.46 + back_ref = 'medium', -- each autoloaded classification automatically refers back to the Medium 1.47 + default_order = '"position"' -- order tracks by SQL expression "position" 1.48 +}