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

Arrays of Composite Types #8

Open
loganb opened this issue Apr 25, 2016 · 10 comments
Open

Arrays of Composite Types #8

loganb opened this issue Apr 25, 2016 · 10 comments

Comments

@loganb
Copy link

loganb commented Apr 25, 2016

Hello,

I just came across this great little gem. I'd like to use it to store arrays of composite types. It looks like that isn't supported right now; is this a planned feature? If so, do you have any thoughts on how it would be implemented? Thanks!

@loganb
Copy link
Author

loganb commented Apr 25, 2016

After more trial-and-error, it looks like if I use the create_table do … end syntax array columns work, however if I directly create the table using CREATE TABLE, it gets confused and fails to save any objects to the table. Any idea what might be going on? Thanks!

@loganb
Copy link
Author

loganb commented Apr 25, 2016

Upon further inspection, it looks like some sort of load issue. If I define a class on the console for a table like so:

logan@bender (OSX) $ bundle exec rails console
Loading development environment (Rails 4.2.5.2)
2.1.7 :001 > class TestTable < ActiveRecord::Base; end
 => nil 
2.1.7 :002 > TestTable.columns

It correctly loads the type. But if I reference a Model object in app/models, it does not. I put the following snippet in my application.rb:

    #For composite type support
    ActiveSupport.on_load :active_record do
       Dir[Rails.root.join('app/composite_types/*.rb')].each { |file| require file }
    end

@loganb
Copy link
Author

loganb commented Apr 25, 2016

Further trial-and-error indicates that if ActiveRecord encounters a column with an array of composite types before encountering a scalar column, it fails to load properly.

@katafrakt
Copy link
Contributor

Hi @loganb! Thanks for reporting this issue and sorry you had to wait such long time for any response. Since I was not directly involved in development of activerecord-postgres-composite-types, could you help me reproduce the problem?

Things I'd like to know:

  • Which Rails version are you using?
  • What complex type did you try to use?
  • What was your CREATE TABLE statement mentioned in your second comment?

@loganb
Copy link
Author

loganb commented May 3, 2016

I'll try to nail down a simple repo case here shortly.

@loustler
Copy link

loustler commented Aug 31, 2018

@katafrakt I have this problem also.

How do I have to solve it?

I executed migration, than receive this message and cannot save to table.

  unknown OID 33556: failed to recognize type of 'families'. It will be treated as String. # when i migrate

  TypeError: can't cast Array to # when i save the instance.

Type Definition

  CREATE TYPE family AS
  (
    name character varying,
    age  integer
  )

Add column to table

  add_column :user, :families, :family, array: true

Rails version

4.2

@katafrakt
Copy link
Contributor

@loustler This has something to do with PostgreSQL version. Which version are you using?

@loustler
Copy link

@katafrakt PSQL version is 9.6.3

@loustler
Copy link

loustler commented Sep 3, 2018

@katafrakt Could you plz keep me updated about this issue?

@katafrakt
Copy link
Contributor

@loustler I wish I could - but please note that I didn't contribute any single line of code to this project. 9.6 should be supported version and my knowledge is probably too limited to debug this easily. Even if I did, I don't have push rights to publish new version to rubygems (@rafalbigaj do you have it?). So I'm sorry, but I'm probably not your man.

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

3 participants