Created
November 1, 2009 21:09
-
-
Save rvalyi/223727 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Basic finders: | |
ProductProduct.find(1) | |
ProductProduct.find([1,2]) | |
ProductProduct.find([1]) | |
ProductProduct.find(:all) | |
ProductProduct.find(:last) | |
#OpenERP domain support: | |
ResPartner.find(:all, :domain=>[['supplier', '=', 1],['active','=',1]]) | |
#OpenERP context support: | |
ProductProduct.find(1, :context => {:my_key => 'value'} | |
#Request params or ActiveResource? equivalence of OpenERP domain (but degraded as only the = operator is supported, else use domain): | |
Partners.find(:all, :params => {:supplier => true}) | |
#Relations (many2one, one2many, many2many) support: | |
SaleOrder.find(1).order_line | |
p = ProductProduct.find(1) | |
p.product_tmpl_id #many2one relation | |
p.tax_ids = [6, 0, [1,2]] #create many2many associations, | |
p.save #assigns taxes with id 1 and 2 as sale taxes, | |
#see OpenERP doc Here http://doc.openerp.com/developer/5_18_upgrading_server/19_1_upgrading_server.html?highlight=many2many | |
#Inherited relations support: | |
ProductProduct.find(1).categ_id #where categ_id is inherited from the ProductTemplate | |
#Load only specific fields support (faster than loading all fields): | |
ProductProduct.find(1, :fields=>["state", "id"]) | |
ProductProduct.find(:all, :fields=>["state", "id"]) | |
ProductProduct.find([1,2], :fields=>["state", "id"]) | |
ProductProduct.find(:all, :fields=>["state", "id"]) | |
even in relations: | |
SaleOrder.find(1).order_line(:fields => ["state"]) | |
#Create: | |
>> pc = ProductCategory.new(:name => 'Categ From Rails!') | |
=> #<ProductCategory:0xb702c42c @prefix_options={}, @attributes={"name"=>"Categ From Rails!"}> | |
>> pc.create | |
=> 14 | |
#Update: | |
>> pc.name = "A new name" | |
>> pc.save | |
#Delete: | |
>> pc.destroy | |
#Call workflow: see code; TODO document | |
#Call aribtrary method: see code; TODO document |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment