My favorites | Sign in
Project Logo
Project hosting will be READ-ONLY Wednesday at 8am PST due to brief network maintenance.
             
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require 'modules/simple_find'

class Kommune < ActiveOIO::Base
include SimpleFind


def skoler
if(self.attributes['skoler'] == nil)
sk = Skole.find(:all,:from => "/danmark/kommuner/#{nr}/skoler")
sk.each do |s|
s.attributes['kommune'] = self
end
self.attributes['skoler'] = sk
end
self.attributes['skoler']
end

def lokaliteter
if(self.attributes['lokaliteter'] == nil)
loks = Lokalitet.find(:all,:from => "/danmark/kommuner/#{nr}/lokaliteter")
loks.each do |l|
l.attributes['kommune'] = self
end
self.attributes['lokaliteter'] = loks
end
self.attributes['lokaliteter']
end

def skoledistrikter
if(self.attributes['skoledistrikter'] == nil)
distr = Skoledistrikt.find(:all,:from => "/danmark/kommuner/#{nr}/skoledistrikter")
distr.each do |d|
d.attributes['kommune'] = self
end
self.attributes['skoledistrikter'] = distr
end
self.attributes['skoledistrikter']
end
end
Show details Hide details

Change log

r19 by christ...@dalager.com on Apr 06, 2008   Diff
Added a bunch of associations - they need
to be DRYed up though.

Now you can do, fx,

nordjylland =
Region.find_by_name('Nordjylland').first
nordjyskeKommuner = nordjylland.kommuner
skoler = nordjylland.kommuner.collect{|k|
k.skoler}.flatten ## finder 278 skoler i
et array
skoler.last.navn ## => "Vrå Skole"
Go to: 
Project members, sign in to write a code review

Older revisions

r13 by christ...@dalager.com on Apr 05, 2008   Diff
Converted project to rails plugin.

Added a basic set of models

Created a module with a
...
All revisions of this file

File info

Size: 1015 bytes, 39 lines
Hosted by Google Code