method
ids_reader
v3.2.13 -
Show latest stable
- Class:
ActiveRecord::Associations::CollectionAssociation
ids_reader()public
Implements the ids reader method, e.g. foo.item_ids for Foo.has_many :items
# File activerecord/lib/active_record/associations/collection_association.rb, line 45
def ids_reader
if loaded? || options[:finder_sql]
load_target.map do |record|
record.send(reflection.association_primary_key)
end
else
column = "#{reflection.quoted_table_name}.#{reflection.association_primary_key}"
relation = scoped
including = (relation.eager_load_values + relation.includes_values).uniq
if including.any?
join_dependency = ActiveRecord::Associations::JoinDependency.new(reflection.klass, including, [])
relation = join_dependency.join_associations.inject(relation) do |r, association|
association.join_relation(r)
end
end
relation.pluck(column)
end
end Related methods
- Instance methods
- add_to_target
- any?
- build
- concat
- count
- create
- create!
- delete
- delete_all
- delete_all_on_destroy
- destroy
- destroy_all
- empty?
- find
- first
- ids_reader
- ids_writer
- include?
- last
- length
- load_target
- many?
- reader
- replace
- reset
- select
- size
- sum
- transaction
- uniq
- writer
- Class methods
- new
- Private methods
-
callback -
callbacks_for -
concat_records -
create_record -
create_scope -
custom_counter_sql -
custom_finder_sql -
delete_or_destroy -
delete_records -
fetch_first_or_last_using_find? -
find_by_scan -
find_target -
first_or_last -
include_in_memory? -
insert_record -
merge_target_lists -
remove_records -
replace_records