tag:blogger.com,1999:blog-6485600373878536861.post9190851404673515316..comments2024-02-19T00:22:44.293-08:00Comments on RailsCraft: Multi-tenanting Ruby on Rails Applications on Heroku - Part IV: using the gem Miliadaudihttp://www.blogger.com/profile/17854126538758831978noreply@blogger.comBlogger4125tag:blogger.com,1999:blog-6485600373878536861.post-19587999296939084812013-05-29T22:07:46.126-07:002013-05-29T22:07:46.126-07:00Q: Do you happen to have an example application wh...Q: Do you happen to have an example application where you use Milia? Something with Tenants, Users, Comments, and possibly some entity that has a join table, where you use the where clause? - anonymous<br /><br />A: yes, look in the test/rails_app directory. A basic working set up is there.daudihttps://www.blogger.com/profile/17854126538758831978noreply@blogger.comtag:blogger.com,1999:blog-6485600373878536861.post-11585576045279152562013-05-29T22:07:11.937-07:002013-05-29T22:07:11.937-07:00Q: In the updatable view ad rules approach, how do...Q: In the updatable view ad rules approach, how do you handle scenarios where you have a table with a unique index (e.g. varchar(50)) and two different tenants want to insert a row with the same key? - anonymous<br /><br />A: That’s a great question and a situation which I hadn’t considered.<br /><br />My initial thoughts are that you’d use a Rails validator which would therefore just check within the context of the tenant. You’d set up your migration DB index specification to be dual: <br /><br /> add_index :profiles, [:tenant_id, :something_else]daudihttps://www.blogger.com/profile/17854126538758831978noreply@blogger.comtag:blogger.com,1999:blog-6485600373878536861.post-73512049711504476692013-05-29T22:06:41.454-07:002013-05-29T22:06:41.454-07:00Q: I've been looking for something like this. ...Q: I've been looking for something like this. This is great information and research. Thank you! - anonymous<br /><br />A: you’re welcome; I hope it’s helpful. let me know if you need assistance implementing milia!daudihttps://www.blogger.com/profile/17854126538758831978noreply@blogger.comtag:blogger.com,1999:blog-6485600373878536861.post-71788885463061390752013-05-29T22:06:04.387-07:002013-05-29T22:06:04.387-07:00[Comments & answers ported from Tumblr blog]
Q...[Comments & answers ported from Tumblr blog]<br />Q: Do you have an example application where you are using Milia? Need to know how to do the join where clause and also how the code should look in the Tenants model? (create_new_tenant, tenant_signup, hooks, etc..). Also should the User model contain belongs_to :tenant? - jgervin<br /><br />A: Hi, yes there is an example application. Look in the test directory. You’ll see a folder called: rails_app, which is a fully set up multi-tenanted application. <br /><br />I don’t quite understand what you mean by “the join where clause” .. could you be more specific? (maybe reference something in the documentation or provide an example?).<br /><br />If you mean how do you do joins? The answer is that joins which occur within the context of a tenant (which most should), usually do not need any additional restrictions; but if the main model referenced is a universal table joined with a tenanted table, then you’d need the following example:<br /><br />User.joins(:posts,:comments).where(:posts => {:title => “wild blue”}).where( where_restrict_tenant( Post, Comment) )<br /><br />where_restrict_tenant( klass1, klass2, … ) is a milia construct.<br /><br />The code in Tenants model depends on a variety of things: are you using devise for authentication or not, do you have a complicated set up sequence for each tenant or not.<br /><br />Yes, the User model should belongs_to :tenant, but I believe that milia inserts that for you. Your migration, however, needs to have a field for tenant_id. And your tenants model should have has_many :posts (for example) for every tenanted table.daudihttps://www.blogger.com/profile/17854126538758831978noreply@blogger.com