On Thursday, September 25, 2014 10:30:13 AM UTC-7, Jerry West wrote:
>
> Hello; can anyone help me, please?
>
> I have a number of identical databases - or nearly so: the minor changes 
> are hidden behind identically structured views that return the same fields 
> but perform joins on different tables.  These views are read-only, though 
> that is not enforced (how would I do that?).
>
> I need to report on the same things for each database, so I use sharding 
> and enumerate over the servers to return records.
>
> Each record "knows" which shard it came from so that associations "just 
> work".  [Aside: how can I find which shard a given dataset is bound to, 
> please?]
>
> However, associations do NOT just work if they reference a view rather 
> than a table.  That is, given a Model...
>
> class VerificationTask < Sequel::Model(:csm_verification_tasks) # itself a 
> view
>   many_to_one :course # a genuine table
>   many_to_one :submission # a view hiding joins between tables
> end
>
> then for a given instance vt = VerificationTask.server(x).first we find 
> vt.course selects correctly: *SELECT * FROM mdl_course WHERE id = <the 
> correct id> LIMIT 1*.  But vt.submission does NOT work: *SELECT * FROM 
> csm_submissions LIMIT 1*.  Notice that there is no id = clause.  
> Naturally this simply picks up the first entry in the view.
>

I don't think this has anything to do with sharding.  My guess is 
Submission.primary_key is nil, since views do not have primary keys.  You 
probably want to use the :primary_key=>:id option in your association, or 
use Submission.set_primary_key :id.

However, I think associations code should raise an error if the associated 
classes's primary key is nil, instead of generating a bogus query.  I'll 
make that change before the next release.

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