Skip to content

Commit

Permalink
Fixed a bug where the SELECT of custom queries would not take priorit…
Browse files Browse the repository at this point in the history
…y on properties in case of name clash.
  • Loading branch information
gaspard committed Apr 11, 2011
1 parent 4319a4d commit 24c6104
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
8 changes: 1 addition & 7 deletions app/models/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -894,6 +894,7 @@ def safe_method_type(signature, receiver = nil)
RubyLess::SafeClass.safe_method_type_for(self, signature)
else
method = signature.first

if type = super
type
elsif method == 'cached_role_ids'
Expand All @@ -902,13 +903,6 @@ def safe_method_type(signature, receiver = nil)
elsif method =~ /^(.+)_((id|zip|status|comment)(s?))\Z/ && !instance_methods.include?(method)
key = $3 == 'id' ? "zip#{$4}" : $2
{:method => "rel[#{$1.inspect}].try(:other_#{key})", :nil => true, :class => ($4.blank? ? Number : [Number])}
elsif receiver && query = receiver.opts[:query]
# Resolve by using information in the SELECT part of the query that found this node
if query.select_keys.include?(method)
{:class => String, :method => "attributes[#{method.inspect}]", :nil => true}
else
nil
end
else
nil
end
Expand Down
19 changes: 15 additions & 4 deletions app/models/virtual_class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -314,11 +314,22 @@ def real_class?
# explicitely declared as safe are safe. If the VirtualClass reflects a virtual
# class, all properties are considered safe.
def safe_method_type(signature, receiver = nil)
if signature.size == 1 && (type = safe_column_types[signature.first])
type
else
real_class.safe_method_type(signature, receiver)

if signature.size == 1
method = signature.first
if receiver && (query = receiver.opts[:query])
if query.select_keys.include?(method)
# Resolve by using information in the SELECT part
# of the custom_query that found this node
return {:class => String, :method => "attributes[#{method.inspect}]", :nil => true}
end
end
if type = safe_column_types[method]
return type
end
end

real_class.safe_method_type(signature, receiver)
end

# Return safe columns including super class's safe columns
Expand Down
4 changes: 4 additions & 0 deletions test/sites/complex/roles.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ DEFAULTS:
icon: ""
type: VirtualClass

Priority:
type: Role
kpath: N

Reference:
kpath: NR
real_class: Node
Expand Down

0 comments on commit 24c6104

Please sign in to comment.