Skip to content
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

Status of the record coder? #70

Open
DanielHeath opened this issue Nov 8, 2022 · 2 comments
Open

Status of the record coder? #70

DanielHeath opened this issue Nov 8, 2022 · 2 comments

Comments

@DanielHeath
Copy link

I'm interested in implementing support for storing arbitrary record types in rows.

I saw that lib/torque/postgresql/coder.rb was removed in cf1c46f (message remove unnecessary code).

Do you recall whether it was working? If I get it running, would a PR be accepted?

@crashtech
Copy link
Owner

Hey there. So that part of the code was removed because newer versions of the PG gem pretty much added all the support needed for the things the coder was doing. So, relying on the PG gem is better than using the previous coder.

BTW, I saw your PR and Composite type is something that I planned on adding to the gem, but using ActiveRecord's composed_of feature, which is quite unknown. So I will hold on that for now.

@DanielHeath
Copy link
Author

DanielHeath commented Nov 13, 2022

composed_of is for mapping multiple columns into a single struct, right? This maps a single column (containing a row value) into a struct, which is not quite the same thing (although I suppose you could use composed_of with a single argument).

This PR also supports instantiating instances of regular ActiveRecord::Base models, if they are stored in a column.

I intend to extend this to support associations - consider:

class Parent < ActiveRecord::Base
  has_many :children, class_name: "Child"
  def self.rolled_up(id)
    where(id: id).
    joins(:children).
    select("parents.*, array_agg(ROW(children.*)) as children").
    group(Parent.columns.map {|c| "#{Parent.table_name}.#{c.name}"})
  end
end
class Child < ActiveRecord::Base
  belongs_to :parent
end

This should preload the children relation with instances of Child.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants