On Tuesday, August 5, 2014 6:11:47 PM UTC+1, Jeremy Evans wrote:
>
> On Tuesday, August 5, 2014 9:36:52 AM UTC-7, Paul Carew wrote:
>>
>> Thanks for taking a look. The following example should illustrate the 
>> issue.
>>
>> require "sequel"
>>
>> # Setup Sequel connection to postgres
>> DB = 
>> Sequel.connect('postgres://username:password@localhost/database_name')
>> DB.extension :pg_array
>>
>> # Define the Record model
>> class Record < Sequel::Model
>>   plugin :json_serializer
>> end
>>
>> # Create the records table if it doesn't exist
>> if !DB.table_exists? :records
>>   DB.create_table :records do
>>     primary_key :id
>>     text :name
>>     integer :seenBy, :type => "integer[]"
>>   end
>> end
>>
>
> This is broken, as it creates the table after creating the model class. 
>  Always create the table first.  However, that's not your issue.
>  
>
>>
>> # JSON representations of data
>> dataNew = {"name"=>"John Smith", "seenBy"=>["1"]}
>> dataUpdate = {"name"=>"John Smith", "seenBy"=>["1", "2"]}
>>
>> #Create a new record
>> newRecord = Record.new(dataNew)
>> newRecord.save
>>
>> #Update record
>>
>> updatedRecord = Record.where(:id => newRecord.id)
>> updatedRecord.update(dataUpdate)
>>
>
> This is Dataset#update, not Model#update, so an error is completely 
> expected (datasets don't typecast, as they don't know the types of their 
> columns).  You probably want:
>
>  updatedRecord = Record.first(:id => newRecord.id)
> updatedRecord.update(dataUpdate)
>
> Thanks,
> Jeremy
>

Such a simple solution in the end!

Thank you very much. Working perfectly now.

Paul


 

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to