Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions activerecord/lib/active_record/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def inherited(child_class) # :nodoc:
end

def find(*ids) # :nodoc:
# byebug
# We don't have cache keys for this stuff yet
return super unless ids.length == 1
return super if block_given? ||
Expand All @@ -169,7 +168,6 @@ def find(*ids) # :nodoc:

key = primary_key

# byebug
statement = cached_find_by_statement(key) { |params|
where(key => params.bind).limit(1)
}
Expand All @@ -186,6 +184,7 @@ def find(*ids) # :nodoc:
end

def find_by(*args) # :nodoc:
# byebug
return super if scope_attributes? || reflect_on_all_aggregations.any?

hash = args.first
Expand Down Expand Up @@ -283,9 +282,7 @@ def cached_find_by_statement(key, &block)
end

def relation
# byebug
relation = Relation.create(self)
# byebug

if finder_needs_type_condition? && !ignore_default_scope?
relation.where!(type_condition)
Expand Down
8 changes: 8 additions & 0 deletions activerecord/lib/active_record/querying.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ def find_by_sql(sql, binds = [], preparable: nil, &block)
class_name: name
}

# binds.each do
# column = ""
# column = binds.first.name unless not binds.first.name
# if self.attribute_names.include? column += "_aip"
# # in this case the query was based on a column that has an _aip column and therefore purposes attached
# end
# end

message_bus.instrument("instantiation.active_record", payload) do
result_set.map { |record| instantiate(record, column_types, &block) }
end
Expand Down
35 changes: 26 additions & 9 deletions activerecord/lib/active_record/relation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,32 @@ class Relation
attr_reader :table, :klass, :loaded, :predicate_builder
# ====================================
# !!! Altered by prails
attr_accessor :skip_preloading_value, :purpose_fields, :for_purpose
attr_accessor :skip_preloading_value, :purpose_fields, :for_purpose, :query_columns
# ====================================
alias :model :klass
alias :loaded? :loaded
alias :locked? :lock_value

def initialize(klass, table: klass.arel_table, predicate_builder: klass.predicate_builder, values: {})
# byebug
@klass = klass
@table = table
@values = values
@offsets = {}
@loaded = false
@predicate_builder = predicate_builder
@delegate_to_klass = false
@for_purpose = -1

# ======================================================
# !!! Added by prails
#
@for_purpose = -1
@query_columns = {}
@purpose_fields = []
@klass.attribute_names.each do |attribute|
if attribute[-4..-1] == "_aip"
@purpose_fields << attribute[0..-5]
end
end
# byebug
# ======================================================
end

Expand Down Expand Up @@ -246,15 +245,12 @@ def explain

# Converts relation objects to Array.
def to_ary
# byebug
records.dup
end
alias to_a to_ary

def records # :nodoc:
# byebug
load
# byebug

# ======================================================
# !!! Added by prails
Expand All @@ -273,8 +269,12 @@ def records # :nodoc:
end
end



# this sanitizes the attributs of the records themselves. This counts for normal relations and also for associations, if there are records left
# checks each attribute's "_aip" field if the purpose is contained
records_to_delete = []

if self.for_purpose and not self.purpose_fields.empty?
@records.each do |record|
record.attributes.each do |k,v|
Expand All @@ -290,13 +290,30 @@ def records # :nodoc:
if not purposes.include? self.for_purpose
record[k] = nil
end

if not self.query_columns.blank?
if self.query_columns.include? k.to_sym
# in this case there was a query condition based on the columns present in @query_columns
# find_by e.g. also uses this as well as .where() queries.
# If records where found based on this but the column was not allowed for the given purpose, we have to delete the whole record
if not purposes.include? self.for_purpose
records_to_delete << record
end
end
end

end
end
end
end
# byebug
@records_dup = @records.dup
records_to_delete.each do |record|
@records_dup.delete(record)
end

@records
# byebug
# @records
@records_dup
end

# Serializes the relation objects Array.
Expand Down
1 change: 0 additions & 1 deletion activerecord/lib/active_record/relation/finder_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ module FinderMethods
# Person.where(name: 'Spartacus', rating: 4).pluck(:field1, :field2)
# # returns an Array of the required fields.
def find(*args)
# byebug
return super if block_given?
find_with_ids(*args)
end
Expand Down
17 changes: 16 additions & 1 deletion activerecord/lib/active_record/relation/query_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ def for(*args)
# byebug
if args.size == 1
# und gott sprach: es darf nur einen purpose geben
self.for_purpose = args.first
if args.first.is_a? Integer
self.for_purpose = args.first
else
raise ArgumentError, "purpose-ID must be of type Integer."
end
else
# hier unterschiedliche exceptions raisen, je nachdem ob keiner oder zu viele purposes angegeben wurden
if args.size < 1
Expand Down Expand Up @@ -606,6 +610,17 @@ def left_outer_joins!(*args) # :nodoc:
# If the condition is any blank-ish object, then #where is a no-op and returns
# the current relation.
def where(opts = :chain, *rest)
# byebug
# ===============================================================
# Added by Prails
#
# ===============================================================
if not opts.blank?
self.query_columns = opts
end

# ===============================================================

if :chain == opts
WhereChain.new(spawn)
elsif opts.blank?
Expand Down