On Tuesday, October 20, 2015 at 11:10:43 AM UTC-7, Jeremy Swartwood wrote:
>
> I'm trying to create a dynamic/generic GET method for a REST api.  My code 
> is working but I want to generalize it a bit.
>
> Essentially I don't want to have to create an instance variable 
> (source_system), and set it outside (ba.source_system = ba[:value]) in an 
> interation, just to use it inside (*sourceSystem: source_system**,*) in a 
> method.  I want to just  use "value" directly inside the model class.
>
> My model class joins to a lookup table of KEY/VALUE.  I can access that 
> just fine with .each do.  However, if I try to access the column in the 
> model, it doesn't exist as one of the columns.
>
> Models::Accounts
>   .where(return_object.params_extractor.where_conditions)
>   .qualify(:account)
>   .association_join(:account_source_values)
>   .select_append(:account_source_values__value___value)
>   .limit(page_opts[:per_page], page_opts[:offset])
>   .each do |ba|
>
>   ba.source_system = ba[:value]
>
>   puts ba.to_hash
>
>
> I can access value when doing an iteration over it and calling ba[:value].
>
> but if I call a method on it inside that iteration:
>
>    - ba.to_hash
>
> it doesn't have access to *value *in the to_hash method.
>
> calling p self.columns doesn't show the joined column t
>
> def to_hash
>   puts self.columns
>   {
>     id: account_id,
>     meta: create_meta,
>     accountNumber: account_ref,
> *    sourceSystem: value**,*
>     isActive: to_bool(active),
>     enrolleeId: enrollee_id,
>     _links: create_links
>   }
> end
>
>
>  
Assuming I'm reading this correctly, and you just want to use sourceSystem 
as the key in the hash, it seems easiest to just alias appropriately in 
your query:

  .select_append(:account_source_values__value___sourceSystem)

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

Reply via email to