Sorry for the misunderstanding, I typed my code wrong. This is what I meant:

puts DB[:users].first[:name]     # => Kaiser

When I print the underlying hash, I see all the values! 

User.first[:name]      # => Kaiser

Maybe my misunderstanding is more with Ruby than sequel. It was my 
understanding that User.first would give me a model I can use with the "." 
accessor.

If I may ask a follow-up:

What is the correct way of accessing these values from within the model?

I am doing the following right now, but it is strange to me:

User.first.get_full_name

# user.rb
def get_full_name
    #return first_name + last_name     # => first_name and last_name are nil
    return self[:first_name] + self[:last_name]     # => Kaiser Pister
end

Again I imagine this is simply because I am a Ruby noob.
Thanks for your help!


On Saturday, October 21, 2017 at 8:51:11 PM UTC-7, Jeremy Evans wrote:
>
> On Saturday, October 21, 2017 at 8:45:51 PM UTC-7, Kaiser Pister wrote:
>>
>> I must have set up my app incorrectly; any help is appreciated.
>>
>> I am connecting to my database successfully and can access all my 
>> tables/values through the datasets I get from DB[:users].
>>
>> However when I try to use the model (eg. User.first), the model has nil 
>> values for all its attributes.
>>
>> Is there some connection I am missing?
>>
>> For more clarity:
>>
>> puts DB[:users].count              # => 24
>> puts DB[:users].first['name']     # => Kaiser
>>
>
> This is very odd.  Sequel uses symbols for the hash keys, not strings.  If 
> you are using something that uses string keys instead of symbol keys (such 
> as an external adapter or extension), then that is what is likely breaking 
> Sequel::Model.
>  
>
>> puts User.all.count                   # => 24
>> puts User.first.name                 # => nil
>>
>
> You could do:
>
> p User.first.values
>
> and see what is in the underlying hash.
>
> Thanks,
> Jeremy
>

On Saturday, October 21, 2017 at 8:51:11 PM UTC-7, Jeremy Evans wrote:
>
> On Saturday, October 21, 2017 at 8:45:51 PM UTC-7, Kaiser Pister wrote:
>>
>> I must have set up my app incorrectly; any help is appreciated.
>>
>> I am connecting to my database successfully and can access all my 
>> tables/values through the datasets I get from DB[:users].
>>
>> However when I try to use the model (eg. User.first), the model has nil 
>> values for all its attributes.
>>
>> Is there some connection I am missing?
>>
>> For more clarity:
>>
>> puts DB[:users].count              # => 24
>> puts DB[:users].first['name']     # => Kaiser
>>
>
> This is very odd.  Sequel uses symbols for the hash keys, not strings.  If 
> you are using something that uses string keys instead of symbol keys (such 
> as an external adapter or extension), then that is what is likely breaking 
> Sequel::Model.
>  
>
>> puts User.all.count                   # => 24
>> puts User.first.name                 # => nil
>>
>
> You could do:
>
> p User.first.values
>
> and see what is in the underlying hash.
>
> Thanks,
> Jeremy
>

On Saturday, October 21, 2017 at 8:51:11 PM UTC-7, Jeremy Evans wrote:
>
> On Saturday, October 21, 2017 at 8:45:51 PM UTC-7, Kaiser Pister wrote:
>>
>> I must have set up my app incorrectly; any help is appreciated.
>>
>> I am connecting to my database successfully and can access all my 
>> tables/values through the datasets I get from DB[:users].
>>
>> However when I try to use the model (eg. User.first), the model has nil 
>> values for all its attributes.
>>
>> Is there some connection I am missing?
>>
>> For more clarity:
>>
>> puts DB[:users].count              # => 24
>> puts DB[:users].first['name']     # => Kaiser
>>
>
> This is very odd.  Sequel uses symbols for the hash keys, not strings.  If 
> you are using something that uses string keys instead of symbol keys (such 
> as an external adapter or extension), then that is what is likely breaking 
> Sequel::Model.
>  
>
>> puts User.all.count                   # => 24
>> puts User.first.name                 # => nil
>>
>
> You could do:
>
> p User.first.values
>
> and see what is in the underlying hash.
>
> Thanks,
> Jeremy
>

On Saturday, October 21, 2017 at 8:51:11 PM UTC-7, Jeremy Evans wrote:
>
> On Saturday, October 21, 2017 at 8:45:51 PM UTC-7, Kaiser Pister wrote:
>>
>> I must have set up my app incorrectly; any help is appreciated.
>>
>> I am connecting to my database successfully and can access all my 
>> tables/values through the datasets I get from DB[:users].
>>
>> However when I try to use the model (eg. User.first), the model has nil 
>> values for all its attributes.
>>
>> Is there some connection I am missing?
>>
>> For more clarity:
>>
>> puts DB[:users].count              # => 24
>> puts DB[:users].first['name']     # => Kaiser
>>
>
> This is very odd.  Sequel uses symbols for the hash keys, not strings.  If 
> you are using something that uses string keys instead of symbol keys (such 
> as an external adapter or extension), then that is what is likely breaking 
> Sequel::Model.
>  
>
>> puts User.all.count                   # => 24
>> puts User.first.name                 # => nil
>>
>
> You could do:
>
> p User.first.values
>
> and see what is in the underlying hash.
>
> Thanks,
> Jeremy
>

On Saturday, October 21, 2017 at 8:51:11 PM UTC-7, Jeremy Evans wrote:
>
> On Saturday, October 21, 2017 at 8:45:51 PM UTC-7, Kaiser Pister wrote:
>>
>> I must have set up my app incorrectly; any help is appreciated.
>>
>> I am connecting to my database successfully and can access all my 
>> tables/values through the datasets I get from DB[:users].
>>
>> However when I try to use the model (eg. User.first), the model has nil 
>> values for all its attributes.
>>
>> Is there some connection I am missing?
>>
>> For more clarity:
>>
>> puts DB[:users].count              # => 24
>> puts DB[:users].first['name']     # => Kaiser
>>
>
> This is very odd.  Sequel uses symbols for the hash keys, not strings.  If 
> you are using something that uses string keys instead of symbol keys (such 
> as an external adapter or extension), then that is what is likely breaking 
> Sequel::Model.
>  
>
>> puts User.all.count                   # => 24
>> puts User.first.name                 # => nil
>>
>
> You could do:
>
> p User.first.values
>
> and see what is in the underlying hash.
>
> Thanks,
> Jeremy
>

-- 
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 https://groups.google.com/group/sequel-talk.
For more options, visit https://groups.google.com/d/optout.

Reply via email to