Hi Rich,

I have never used this Gem but I did notice it a while ago and it seems to be 
under active development. It might be of use to you:
https://github.com/drnic/composite_primary_keys

I'm not totally sure that any kind of gem is really required here. One thing I 
can say is that even if ActiveRecord doesn't support composite primary keys, I 
would still enforce them at the database level to underpin whatever strategy 
you use. You can then use the Account class that as the owning parent to be a 
factory for the Invoices and shell out IDs from there which the database will 
enforce uniqueness on based on the combination of it and the account_id. If you 
do that building inside a transaction and increment your sequence in there as 
well you should be pretty good.

Cheers,

Adam 

-- 
Adam Boas
e: [email protected]
m: +61 457 741 117


On Wednesday, 3 April 2013 at 8:29 PM, Rich Buggy wrote:

> Hi everyone,
> 
> I'm building a multi-tenant application and I'd like some of the ID's to be 
> per tenant. It's using the path based multi-tenant approach. For example - 
> /:account/invoices/:id
> 
> I've got the routing working correctly but the ID's are being generated 
> automatically so they are unique across the application, not just the tenant. 
> This isn't ideal because each tenant should start from 1.
> 
> I already store the next id in the tenant table so they can choose to start 
> from a number other than 1. This is important as someone with existing data 
> may decide to not start from 1. I think there are a number of ways I can deal 
> with this.
> 
> 1. If I was doing this without rails I'd make the tenant_id + id a composite 
> field and set the id manually when creating the record. Is there are an easy 
> way to do this with rails?
> 
> 2. I could add number field and accept that number != id. This is easy but 
> ugly because /demo/invoices/123456 could be invoice 1
> 
> 3. I could add a number field and try to muck with the routing so it used 
> number instead of id
> 
> Does anyone know of a good guide or blog post on how to do this?
> 
>     Rich 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Ruby or Rails Oceania" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> (mailto:[email protected]).
> To post to this group, send email to [email protected] 
> (mailto:[email protected]).
> Visit this group at http://groups.google.com/group/rails-oceania?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>  
>  

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
or Rails Oceania" 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/rails-oceania?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to