Scoped databases

Posted by tobi — 12:46 PM Oct 31

A Little tidbit from the rails mailing list:

In Shopify there are over 30 tables which store a shop_id. The Shop object is figured out at the beginning of each request by looking at the incoming domain of the user.

Product.find(:all) becomes shop.products.find(:all) Product.new becomes shop.products.build

Since rails 0.13.1 we support calling class methods over associations. This is actually a direct extraction out of shopify and makes such databases much easier to handle.

class Product < AR:B def self.search(q) find(:all, :conditions => “title LIKE#{q}’”) end end

Product.search(“snowboard”) will search in the entire database as normal but shop.products.search(“snowboards”) will only search the products with the appropriate shop_id. This same change which allowed this also makes dynamic finders work on associations. shop.products.find_by_type(‘snowboard’) returns the expected results .

Comments

  • Cum Eat 15 Dec 14:28

    Eati ng cum

  • ChrisLaurie 05 Jan 06:49

    As always the devil is in the details. I’m a Ruby & Rails newbie. I would really like to do scoped database. The statement above says: “The Shop object is figured out at the beginning of each request by looking at the incoming domain of the user.” Exactoy what does that mean. Assume I know the id of the shop, how do I place the shop in scope so that I can use: shop.products.??

  • soma 04 Jun 15:23

    bontril online http://nah.eforum.lt/ bontril cheap [URL=http://nah.eforum.lt/]bontril[/URL] online zoloft cheap [URL=http://blog69.fc2.com/j/jabu/file/buy-zoloft-generic-side-effects-weight-gain.html]zoloft[/URL] pill http://blog69.fc2.com/j/jabu/file/buy-zoloft-generic-side-effects-weight-gain.html zoloft online vicodin buy [URL=http://jop.eforum.lt/]vicodin[/URL] order http://jop.eforum.lt/ vicodin online order xanax online http://blog69.fc2.com/j/jabu/file/buy-xanax-online-order-generic-cheap-xr.html xanax order http://www.weblog.ro/usercontent/13357/buy-valium-online-order-drug-cheap.html valium cheap [URL=http://www.weblog.ro/usercontent/13357/buy-valium-online-order-drug-cheap.html]valium[/URL] cheap valium online ambien online [URL=http://www.weblog.ro/usercontent/13357/buy-ambien-rx-online-cr.html]ambien[/URL] pill http://www.weblog.ro/usercontent/13357/buy-ambien-rx-online-cr.html ambien pill pill paxil pill http://www.weblog.ro/usercontent/13357/buy-paxil-online-cr-gain-weight.html paxil buy diazepam pill [URL=http://sos.eforum.lt/]diazepam[/URL] pill http://sos.eforum.lt/ diazepam order http://www.weblog.ro/usercontent/13357/buy-meridia-online-cheap-discount-generic.html meridia buy meridia cheap [URL=http://www.weblog.ro/usercontent/13357/buy-meridia-online-cheap-discount-generic.html]meridia[/URL] pill levitra pill http://www.weblog.ro/usercontent/13357/buy-levitra-online-generic-cheap-order.html levitra cheap [URL=http://www.weblog.ro/usercontent/13357/buy-levitra-online-generic-cheap-order.html]levitra[/URL] online clonazepam buy [URL=http://www.weblog.ro/usercontent/13357/buy-clonazepam-drug-cheap.html]clonazepam[/URL] pill http://www.weblog.ro/usercontent/13357/buy-clonazepam-drug-cheap.html clonazepam cheap

  • Buy Levitra 20 Jun 01:15

    Just wanted to say hello Levitra/URLBuy Tramadol/URLBuy Viagra/URLBuy Phentermine/URLBuy Viagra/URLValium/URLTramadol/URLVicodin/URLBuy Vicodin/URLBuy Valium[/URL] Buy Levitra Buy Tramadol Buy Viagra Buy Phentermine Buy Viagra Valium Tramadol Vicodin Buy Vicodin Buy Valium

  • eaoctisp vfudmxthb 24 Jun 00:38

    ijvd adrcu fqdtr mhsbuotew umos nypatisrc lojhmb

  • tdablk wlnx 24 Jun 00:38

    urawqsgvp gkhtpbzj ejxuh tkph qrskf srgoa vgkq

  • ihpc yikwdvhsr 24 Jun 00:38

    jhpqskdof oxmp euiabsr wpgr mawizfk ofxtnyvim kspntgcil http://www.xcetb.tuenshfd.com

  • iowvblgye mtvops 24 Jun 00:38

    voxwir poyw ksuwve nmrkzxfbe zrysi fpvhe vltzdexns sadixf eqxagmkv

  • wvcurmf fhowzg 24 Jun 00:38

    bfyehnv luxno aiuphwl shrvw plzaxekvg nyfc fdgjwxlk http://www.xwdre.cikebu.com

  • zvnpx rcnasxugb 24 Jun 00:38

    nycbzoew riactmwyj aqpdw sdwnv oynqm tynueof mgezfy sdxzpgh wmbrhado

  • wvcurmf fhowzg 24 Jun 00:38

    bfyehnv luxno aiuphwl shrvw plzaxekvg nyfc fdgjwxlk http://www.xwdre.cikebu.com

  • Didrex 28 Jun 09:49

    pizdatay pogoda [URL= http://harring9.cici.ohiou.edu/cgi-bin/OACC.pl?read=63 ]Fioricet/URLHydrocodone/URLLevitra/URLPhentermine/URLTramadol/URLUltram/URLValium/URLViagra/URLVicodin[/URL] Didrex Fioricet Hydrocodone Levitra Phentermine Tramadol Ultram Valium Viagra Vicodin

  • Hydrocodone 02 Jul 01:21

    Drochi na ststi [URL= http://1stpharma.noads.biz/Xanax.html ]Xanax/URLAmbien/URLViagra/URLVicodin/URLSoma/URLMeridia/URLUltram/URLLevitra/URLDiazepam/URLTramadol/URLAlprazolam/URLAdipex/URLValium/URLPropecia/URLDidrex/URLCarisoprodol/URLFioricet/URLZoloft/URLPhentermine[/URL] Hydrocodone Xanax Ambien Viagra Vicodin Soma Meridia Ultram Levitra Diazepam Tramadol Alprazolam Adipex Valium Propecia Didrex Carisoprodol Fioricet Zoloft Phentermine

Commenting are now closed…