Improved code layout.

This commit is contained in:
Martin Edenhofer 2012-08-20 15:21:15 +02:00
parent 8b858dad99
commit 48c92b8a71

View file

@ -1,4 +1,5 @@
class Link < ActiveRecord::Base class Link < ActiveRecord::Base
has_many :link_types
#before_create :check_object #before_create :check_object
#after_create :after_create, :cache_delete #after_create :after_create, :cache_delete
@ -6,23 +7,32 @@ class Link < ActiveRecord::Base
#after_destroy :cache_delete #after_destroy :cache_delete
=begin =begin
Link.add(:link_types_id=>12,
Link.add(
:link_types_id => 12,
:link_object_source => 'Ticket', :link_object_source => 'Ticket',
:link_object_source_value => 1, :link_object_source_value => 1,
:link_object_target => 'Ticket', :link_object_target => 'Ticket',
:link_object_target_value=> 1) :link_object_target_value => 1
)
Link.add(:link_types_id=>12, Link.add(
:link_types_id => 12,
:link_object_source_id => '1', :link_object_source_id => '1',
:link_object_source_value => 1, :link_object_source_value => 1,
:link_object_target_id => '1', :link_object_target_id => '1',
:link_object_target_value=> 1) :link_object_target_value => 1,
)
Link.get_links_for_source_object(:link_object => 'Ticket', Link.get_links_for_source_object(
:link_object_value => 1) :link_object => 'Ticket',
:link_object_value => 1
)
Link.get_links_for_target_object(:link_object => 'Ticket', Link.get_links_for_target_object(
:link_object_value => 1) :link_object => 'Ticket',
:link_object_value => 1,
)
Link.delete_link_by_source( :source_value => 1 ) Link.delete_link_by_source( :source_value => 1 )
@ -31,7 +41,6 @@ class Link < ActiveRecord::Base
Link.delete_all_links_by_value( :object_value => 1 ) Link.delete_all_links_by_value( :object_value => 1 )
=end =end
has_many :link_types
def self.get_links_for_source_object(data) def self.get_links_for_source_object(data)
linkobject_id = self.get_linktype_by_name( :name => data[:link_object] ) linkobject_id = self.get_linktype_by_name( :name => data[:link_object] )
@ -49,6 +58,7 @@ class Link < ActiveRecord::Base
def self.add(data) def self.add(data)
if data.has_key?(:link_object_source) if data.has_key?(:link_object_source)
# it exists we have to delete it # it exists we have to delete it
linkobject_id = self.get_linktype_by_name( :name => data[:link_object_source] ) linkobject_id = self.get_linktype_by_name( :name => data[:link_object_source] )
data[:link_object_source_id] = linkobject_id data[:link_object_source_id] = linkobject_id
@ -80,7 +90,6 @@ class Link < ActiveRecord::Base
private private
def self.get_linktype_by_name(data) def self.get_linktype_by_name(data)
linkid = Link::Object.where(:name=>data[:name]).first linkid = Link::Object.where(:name=>data[:name]).first
if linkid if linkid
return linkid.id return linkid.id