-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Is there a way to not include associated records? #67
Comments
I think this is something that is happening because of the values of attributes that happen to be other AR objects so we would likely need to add a configuration option for this and then check for nested AR objects and halt the recursion. |
@aguynamedben I'm not actively using Rails or AR. What other recursive values are you seeing? If you see other |
@aguynamedben can you provide a minimal app where the issue you reported occurs? I was able to reproduce the same output by adding another column named 'users' to #<Organization:0x00007fe114059130> {
:id => 1,
:name => "Company",
:users => [
[0] #<User:0x00007fe11404dd58> {
:id => 1,
:name => "Robert",
:organization_id => 1,
:created_at => Fri, 03 Dec 2021 12:07:37 UTC +00:00,
:updated_at => Fri, 03 Dec 2021 12:07:37 UTC +00:00
}
],
:created_at => Fri, 03 Dec 2021 12:07:16 UTC +00:00,
:updated_at => Fri, 03 Dec 2021 12:07:16 UTC +00:00
} Although it's a unlikely scenario it can be solved by ignoring the 'users' column or don't use class Organization < ApplicationRecord
has_many :users
self.ignored_columns = %w(users)
end def awesome_active_record_instance(object)
return object.inspect unless defined?(::ActiveSupport::OrderedHash)
return awesome_object(object) if @options[:raw]
data = if object.class.column_names == object.attributes.keys
object.class.column_names.each_with_object(::ActiveSupport::OrderedHash.new) do |name, hash|
if object.has_attribute?(name) || object.new_record?
value = object.read_attribute(name) if object.respond_to?(name)
hash[name.to_sym] = value
end
end
else
object.attributes
end
[awesome_simple(object.to_s, :active_record_instance), awesome_hash(data)].join(' ')
end |
My project users Rails, and has User and Organization models. An Organization can have many Users.
When I run
ap Organization.first
, I see the organization printed, but I also see nested data fororganization.user
. Is there a way to tell amazing_print to not recursively print records from associations?.aprc supports
but that appears to be something different. With it set to false I see recursive values from ActiveRecord relationships printed.
Thanks again for maintaining this library. 🙏
The text was updated successfully, but these errors were encountered: