On Jun 9, 10:59 pm, Hiten <[email protected]> wrote:
> On Jun 3, 9:40 pm, Jeremy Evans <[email protected]> wrote:
>
> > On Jun 3, 6:23 pm, Hiten <[email protected]> wrote:
>
> > > On Jun 2, 8:01 pm, Jeremy Evans <[email protected]> wrote:
> > > What would you do in a situation where the particular table had no
> > > relation to the id? For instance, each row is identified by a table
> > > number and id (e.g., [ 7 , 1234 ] would signify Table07 and row id
> > > 1234).
>
> > In that case, instead of basing it on the id, you would just use the
> > table number:
>
> >   def this
> >     super.from(:"TABLE#{sprintf('%03i', table_number)}")
> >   end
>
> Are you assuming that table_number is a column? If that's not the
> case, where would table_number be accessible?

Yes, that was the assumption.  It wouldn't have to be a column, it
could be any instance method for the model.

> When a model instance is created with from(), is that table name kept
> somewhere?
>
> Ideally, I'd be able to do:
>
>   model_instance.server(:shard1).from(:table1).first.this.first_source
>      # => :table1 #(does not happen)
>
> However, this seems to not be the case. It always returns the table
> name of the model (i.e., what was defined in the class definition).

Take a look at the implementation of server in the sharding plugin.
The same approach would work for from.

> This works though:
>
>   model_instance.server(:shard1).from(:table1).naked.first_source
>      # => :table1
>
> What's the right way to proceed?

Depends on your app.  Instead of giving hypotheticals, can you
describe the actual sharding you want to use in your app.  If I knew
that I could probably suggest something.

Jeremy

-- 
You received this message because you are subscribed to the Google Groups 
"sequel-talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sequel-talk?hl=en.

Reply via email to