webmcp
diff demo-app/model/genre.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/genre.lua Sun Oct 25 12:00:00 2009 +0100 1.3 @@ -0,0 +1,25 @@ 1.4 +Genre = mondelefant.new_class() 1.5 +Genre.table = 'genre' 1.6 + 1.7 +Genre:add_reference{ 1.8 + mode = '1m', -- one (1) Genre is used for many (m) Classifications 1.9 + to = "Classification", -- name of referenced model (using a string instead of reference avoids auto-loading here) 1.10 + this_key = 'id', -- own key in genre table 1.11 + that_key = 'genre_id', -- other key in classification table 1.12 + ref = 'classifications', -- name of reference 1.13 + back_ref = 'genre', -- each autoloaded Classification automatically refers back to the Genre 1.14 + default_order = '"media_id"' -- order Classifications by SQL expression "media_id" 1.15 +} 1.16 + 1.17 +Genre:add_reference{ 1.18 + mode = 'mm', -- many (m) Genres belong to many (m) Medium entries 1.19 + to = "Medium", -- name of referenced model (quoting avoids auto-loading here) 1.20 + this_key = 'id', -- (primary) key of genre table 1.21 + that_key = 'id', -- (primary) key of medium talbe 1.22 + connected_by_table = 'classification', -- table connecting genres with media 1.23 + connected_by_this_key = 'genre_id', -- key in connection table referencing genres 1.24 + connected_by_that_key = 'medium_id', -- key in connection table referencing media 1.25 + ref = 'media', -- name of reference 1.26 + back_ref = nil, -- not used for mm relation! 1.27 + default_order = '"medium"."name", "medium"."id"' -- mm references need qualified names in SQL order expression! 1.28 +}