1.配置文件独立,并且精简,位于 config/rope.yml里面
参数说明
development:
redis_cache: :on
redis_cache_second: 60
target_url: localhost:3334
redis_host: cloud-service
lock_cycle: 30
production:
redis_cache: :on
redis_cache_second: 60
target_url: in.rccchina.com
redis_host: cloud-service
lock_cycle: 120
redis_cache: 缓存开关, 建议打开,本次升级对于缓存有比较大的提升,许多功能都基于redis
redis_cache_second: 缓存的时间(秒)
针对缓存,现在可以在模型里面写 redis_cache :off
来关闭该模型的缓存,或者你希望缓存时间长或短可以用 redis_cache :on, 120
来调整缓存时间
target_url:目标地址
redis_host: redis的域名
redis_port: redis的端口,不写是6379
lock_cycle: 本次升级特点之一,当目标系统(reach)发生意外,系统自动将api锁死,此时调用rope_api的接口会抛出一个错误Reach::Rope::ApiError
,以此来防止对reach造成进程卡死的影响,这个参数就是锁死的时间,也可以执行Reach::Rope._unlock!
来主动解锁
移除了redis_class
2 懒加载查询语句 where, select, order...
使用方法
r = Reach::Project.where(:id => [17,12234,45567,12234,54467,54468,54469]).order('updated_at desc').where("created_at < '2014-01-01 00:00'").page(1).per_page(30)
=>#<Reach::Project::RopeRelation: records: [#<Reach::Project {"id"=>54467, "projectid"=>81384, "last"=>0, "project_name"=>"Hangzhou Qingshui Apartment: Phase 5", "l_project_name"=>"杭州清水公寓: 五期", "region_id"=>16, "province_id"=>34, "city_id"=>1036, "l_province"=>"浙江省", "l_town"=>"杭州市", "country_id"=>8, "town_id"=>nil, "address"=>"Desheng Road", "l_address"=>"德胜路", "created_at"=>"2007-10-09T14:35:08+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:35:08+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>1, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"兴建三幢11层高的部份装修的综合楼,每幢设有一个单层高的地下室,总建筑面积大约为30,000平方米,包括:\r\n\r\n*第一层至第三层为商业用房及物业办公楼\r\n*其它层为住宅楼", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"兴建三幢11层高的部份装修的综合楼,每幢设有一个单层高的地下室,总建筑面积大约为30,000平方米,包括:\r\n\r\n<li>第一层至第三层为商业用房及物业办公楼\r\n<li>其它层为住宅楼", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>54469, "projectid"=>81386, "last"=>0, "project_name"=>"Relocation Of Qianan Jianchang Ying Senior High School", "l_project_name"=>"迁安市建昌营高级中学迁建工程", "region_id"=>13, "province_id"=>5, "city_id"=>99, "l_province"=>"河北省", "l_town"=>"唐山市", "country_id"=>8, "town_id"=>nil, "address"=>"West of Tuoxin Road, North of Yuehua Road, Jianchang Ying", "l_address"=>"建昌营镇跃华路北侧, 拓新路西侧", "created_at"=>"2007-10-09T14:35:08+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:35:08+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>1, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"一项教育发展,总建筑面积为28,830平方米,包括:\r\n\r\n*一幢五层高的教学楼\r\n*两幢五层高、简单装修的学生宿舍楼\r\n*一幢五层高、简单装修的教师公寓楼\r\n*一幢三层高的食堂", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"一项教育发展,总建筑面积为28,830平方米,包括:\r\n\r\n<li>一幢五层高的教学楼\r\n<li>两幢五层高、简单装修的学生宿舍楼\r\n<li>一幢五层高、简单装修的教师公寓楼\r\n<li>一幢三层高的食堂", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>54468, "projectid"=>81385, "last"=>0, "project_name"=>"Hejian Yingzhou International Hotel (Five Stars)", "l_project_name"=>"河间市瀛州国际大酒店 (五星级)", "region_id"=>13, "province_id"=>5, "city_id"=>226, "l_province"=>"河北省", "l_town"=>"沧州市", "country_id"=>8, "town_id"=>nil, "address"=>"Crossing Of Jingkai Road And Beihuan Road", "l_address"=>"京开路与北环路交叉口", "created_at"=>"2007-10-09T14:35:08+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:35:08+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>4, "project_status_id"=>1, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"兴建两幢楼,总建筑面积为23,000平方米,包括:\r\n\r\n*一幢13层高的、精装修的五星级酒店,设有一个单层的地下室,包括会议中心和提供136间客房\r\n*一幢三层高的、精装修的裙楼,设有洗浴中心和餐厅", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"兴建两幢楼,总建筑面积为23,000平方米,包括:\r\n\r\n<li>一幢13层高的、精装修的五星级酒店,设有一个单层的地下室,包括会议中心和提供136间客房\r\n<li>一幢三层高的、精装修的裙楼,设有洗浴中心和餐厅", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>45567, "projectid"=>72484, "last"=>0, "project_name"=>"Zhouyou Complex Material Co Ltd: Plant Of Prase 1", "l_project_name"=>"洲友复合材料有限公司: 一期厂房", "region_id"=>16, "province_id"=>32, "city_id"=>900, "l_province"=>"上海", "l_town"=>"青浦区", "country_id"=>8, "town_id"=>nil, "address"=>"Industry garden district west pioneer park C2 plot", "l_address"=>"工业园区西部创业园C2地块", "created_at"=>"2007-10-09T14:23:19+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:23:19+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>1, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"兴建一幢一至两层高、部分装修的厂房,设有办公设施,总建筑面积为16,043平方米,将安装玻璃幕墙。", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"兴建一幢一至两层高、部分装修的厂房,设有办公设施,总建筑面积为16,043平方米,将安装玻璃幕墙。", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>]>
查询懒加载,只有在each,first,last...等方法调用后才回去reach调取,page默认为1,per_page默认为20
关于includes
老版本中,一个列表要是还需要调用其他关联表,性能就会比较差(n+1),本次升级新增预加载方法
class Reach::Project < Reach::Rope
has_many :firm_tenders, class_name: "Reach::Firmtender", foreign_key: :project_id
has_many :project_news, class_name: "Reach::ProjectNews", foreign_key: :projectid
end
r = Reach::Project.where('1=1').includes(:project_news, :firm_tenders)
=>#<Reach::Project::RopeRelation: records: [#<Reach::Project {"id"=>1, "projectid"=>272417, "last"=>0, "project_name"=>"Beijing Changping District Shahe Town South of Xishatun Part Plot Public Renting Housing Project of Beijing Jinhe Water Resources Construction Co., Ltd.", "l_project_name"=>" 北京市昌平区沙河镇西沙屯南侧局部地块公租房项目 (北京金河水务建设有限公司)", "region_id"=>13, "province_id"=>3, "city_id"=>48, "l_province"=>"北京", "l_town"=>"昌平区", "country_id"=>8, "town_id"=>nil, "address"=>"South to Changping Jinhe Road, North to Higher Education Park North No.1 Street, West to Dongsha Hexi No.2 Road, East to Dongshahe West Road, South of Xishatun, Shahe Town", "l_address"=>"沙河镇西沙屯南侧,东至东沙河西路,西至东沙河西二路,北至高教园北一街,南至昌平金河路", "created_at"=>"2012-02-08T11:45:43+08:00", "created_by"=>16244, "updated_at"=>"2012-04-13T09:44:44+08:00", "updated_by"=>3, "production_stage_id"=>1, "project_stage_id"=>3, "project_status_id"=>1, "postcode"=>nil, "class_type"=>2, "local_remarks"=>"该项目为占地面积为135,540平方米,总建筑面积229,915平方米,包括:\r\n\r\n*18幢15至21层高,无装修的住宅楼,设有2层高的地下室和停车场,提供百余个停车位\r\n*1幢17层高,简单装修的办公楼,设有2层高的地下室和停车场\r\n*1至3层高,简单装修的社区卫生中心\r\n*1幢3层高,简单装修的幼儿园\r\n*1至2层高,无装修的配套底商和公建\r\n\r\n部分建材和配置包括:\r\n\r\n*安装数部电梯\r\n*外墙涂料、面砖及玻璃\r\n*安装大型中央空调\r\n*供暖方式采用燃气壁挂炉\r\n\r\n备注:该项目总投资114430万元", "lastpublished"=>"2012-04-13T09:44:44+08:00", "local_remarks_text"=>"该项目为占地面积为135,540平方米,总建筑面积229,915平方米,包括:\r\n\r\n<li>18幢15至21层高,无装修的住宅楼,设有2层高的地下室和停车场,提供百余个停车位\r\n<li>1幢17层高,简单装修的办公楼,设有2层高的地下室和停车场\r\n<li>1至3层高,简单装修的社区卫生中心\r\n<li>1幢3层高,简单装修的幼儿园\r\n<li>1至2层高,无装修的配套底商和公建\r\n\r\n部分建材和配置包括:\r\n\r\n<li>安装数部电梯\r\n<li>外墙涂料、面砖及玻璃\r\n<li>安装大型中央空调\r\n<li>供暖方式采用燃气壁挂炉\r\n\r\n备注:该项目总投资114430万元", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>2, "projectid"=>85595, "last"=>0, "project_name"=>"Phase 3 Of Villas for Shanghai Xingyue Real Estate Co Ltd", "l_project_name"=>"(别墅3期) (上海兴跃房地产有限公司)", "region_id"=>16, "province_id"=>32, "city_id"=>891, "l_province"=>"上海", "l_town"=>"闵行区", "country_id"=>8, "town_id"=>nil, "address"=>"The Crossing of Mingzhong Road and Mingxing Road", "l_address"=>"明中路明兴路口", "created_at"=>"2007-10-09T14:41:05+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:41:05+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>1, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"兴建100幢两层高无装修别墅,总建筑面积为60,000平方米。\r\n\r\n部份建筑材料包括:\r\n\r\n*外墙涂料\r\n*外墙石材", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"兴建100幢两层高无装修别墅,总建筑面积为60,000平方米。\r\n\r\n部份建筑材料包括:\r\n\r\n<li>外墙涂料\r\n<li>外墙石材", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35771, "projectid"=>62688, "last"=>0, "project_name"=>"Railway Equipment Factory: Phase 1", "l_project_name"=>"Railway Equipment Factory: Phase 1", "region_id"=>16, "province_id"=>32, "city_id"=>891, "l_province"=>"上海", "l_town"=>"闵行区", "country_id"=>8, "town_id"=>nil, "address"=>"Xin Zhuang Industrial Zone", "l_address"=>"Xin Zhuang Industrial Zone", "created_at"=>"2007-10-09T14:10:56+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:56+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"Phase 1 is to contain 4,000 square meters of floor space.", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"Phase 1 is to contain 4,000 square meters of floor space.", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35772, "projectid"=>62689, "last"=>0, "project_name"=>"Stainless Steel Sheet Plant(Phase 1)", "l_project_name"=>"Stainless Steel Sheet Plant(Phase 1)", "region_id"=>16, "province_id"=>32, "city_id"=>894, "l_province"=>"Shanghai", "l_town"=>"浦东新区", "country_id"=>8, "town_id"=>nil, "address"=>nil, "l_address"=>nil, "created_at"=>"2007-10-09T14:10:56+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:56+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"Phase 1 is to contain 30,000 square meters of floor space.", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"Phase 1 is to contain 30,000 square meters of floor space.", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35773, "projectid"=>62690, "last"=>0, "project_name"=>"Parkview Place: Phase 3", "l_project_name"=>"PARKVIEW PLACE: PHASE 3", "region_id"=>15, "province_id"=>21, "city_id"=>2130, "l_province"=>"广东省", "l_town"=>"广州市", "country_id"=>8, "town_id"=>nil, "address"=>"148 Dong Fong Xi Road, Yuexi", "l_address"=>"148 Dong Fong Xi Road, Yuexi", "created_at"=>"2007-10-09T14:10:56+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:56+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>1, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"A total of three residential towers with a total floor space of 58,000 square meters and a one-level basement.", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"A total of three residential towers with a total floor space of 58,000 square meters and a one-level basement.", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35774, "projectid"=>62691, "last"=>0, "project_name"=>"Haier Industrial Park: Phase 2", "l_project_name"=>"HAIER INDUSTRIAL PARK: PHASE 2", "region_id"=>16, "province_id"=>2, "city_id"=>1145, "l_province"=>"Anhui", "l_town"=>"合肥市", "country_id"=>8, "town_id"=>nil, "address"=>"Hefei Economic and Technological Development Zone", "l_address"=>"Hefei Economic and Technological Development Zone", "created_at"=>"2007-10-09T14:10:56+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:56+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>3, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"Phase 2 is to contain two plants.The total floor space of each plant will be 36,000 square meters.", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"Phase 2 is to contain two plants.The total floor space of each plant will be 36,000 square meters.", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35775, "projectid"=>62692, "last"=>0, "project_name"=>"Zhong Guan Cun Science And Technology Park: Software Center", "l_project_name"=>"ZHONG GUAN CUN SCIENCE AND TECHNOLOGY PARK: SOFTWARE CENTER", "region_id"=>13, "province_id"=>3, "city_id"=>42, "l_province"=>"北京", "l_town"=>"海淀区", "country_id"=>8, "town_id"=>nil, "address"=>"Zhongguancun", "l_address"=>"Zhongguancun", "created_at"=>"2007-10-09T14:10:56+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:56+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>2, "project_status_id"=>nil, "postcode"=>"100101", "class_type"=>nil, "local_remarks"=>"A software center to be built in the science and technology park with 400,000 square meters of floor space on a 119-hectare site. This software center will have broadband communication facilities and will provide environmentally-friendly and enenrgy-saving offices. ", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"A software center to be built in the science and technology park with 400,000 square meters of floor space on a 119-hectare site. This software center will have broadband communication facilities and will provide environmentally-friendly and enenrgy-saving offices. ", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35776, "projectid"=>62693, "last"=>0, "project_name"=>"Binbo Expressway Yellow River Bridge", "l_project_name"=>"BINBO EXPRESSWAY YELLOW RIVER BRIDGE", "region_id"=>16, "province_id"=>13, "city_id"=>1649, "l_province"=>"Shandong", "l_town"=>"滨州市", "country_id"=>8, "town_id"=>nil, "address"=>nil, "l_address"=>nil, "created_at"=>"2007-10-09T14:10:56+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:56+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>4, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"A 570-kilometer, four-lane bridge.", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"A 570-kilometer, four-lane bridge.", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35777, "projectid"=>62694, "last"=>0, "project_name"=>"Hangzhou Xiasha Higher Education Township: Western District", "l_project_name"=>"杭州下沙高校园区: 西区", "region_id"=>16, "province_id"=>34, "city_id"=>1036, "l_province"=>"浙江省", "l_town"=>"杭州市", "country_id"=>8, "town_id"=>nil, "address"=>"Xiasha New City", "l_address"=>"下沙新城", "created_at"=>"2007-10-09T14:10:56+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:56+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>4, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"西区占地4平方公里,将兴建6所学院及多幢宿舍,总建筑面积为1,900,000平方米。", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"西区占地4平方公里,将兴建6所学院及多幢宿舍,总建筑面积为1,900,000平方米。", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35778, "projectid"=>62695, "last"=>0, "project_name"=>"Yantian Administration And Cultural Center", "l_project_name"=>"YANTIAN ADMINISTRATION AND CULTURAL CENTER", "region_id"=>15, "province_id"=>21, "city_id"=>2157, "l_province"=>"广东省", "l_town"=>"深圳市", "country_id"=>8, "town_id"=>nil, "address"=>"Yantian", "l_address"=>"Yantian", "created_at"=>"2007-10-09T14:10:56+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:56+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>4, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"The development is to contain offices and recreational facilities. There will be 83,000 square meters of floor space.\r\n\r\n", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"The development is to contain offices and recreational facilities. There will be 83,000 square meters of floor space.\r\n\r\n", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35779, "projectid"=>62696, "last"=>0, "project_name"=>"Zhuhai Tv Center", "l_project_name"=>"珠海电视中心", "region_id"=>15, "province_id"=>21, "city_id"=>2165, "l_province"=>"广东省", "l_town"=>"珠海市", "country_id"=>8, "town_id"=>nil, "address"=>"Xiangzhou", "l_address"=>"香洲", "created_at"=>"2007-10-09T14:10:56+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:56+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"兴建一幢4层高电视中心,设有制作室、相关制作设施及办公室,总建筑面积为27,000平方米。", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"兴建一幢4层高电视中心,设有制作室、相关制作设施及办公室,总建筑面积为27,000平方米。", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35780, "projectid"=>62697, "last"=>0, "project_name"=>"Dalian Exhibition Center (3 Stars & 5 Stars)", "l_project_name"=>"DALIAN EXHIBITION CENTER (3 STARS & 5 STARS)", "region_id"=>13, "province_id"=>10, "city_id"=>536, "l_province"=>"Liaoning", "l_town"=>"大连市", "country_id"=>8, "town_id"=>nil, "address"=>"Xinghaiwan", "l_address"=>"Xinghaiwan", "created_at"=>"2007-10-09T14:10:56+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:56+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"The whole development is to contain:\r\n\r\n* an exhibition center with 80,000 square meters of floor space\r\n* a three-star hotel with 70,000 square meters of floor space\r\n* a five-star hotel with 80,000 square meters of floor space\r\n* other related facilities\r\n\r\nThere will be 450,000 square meters of floor space.", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"The whole development is to contain:\r\n\r\n<li> an exhibition center with 80,000 square meters of floor space\r\n<li> a three-star hotel with 70,000 square meters of floor space\r\n<li> a five-star hotel with 80,000 square meters of floor space\r\n<li> other related facilities\r\n\r\nThere will be 450,000 square meters of floor space.", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35781, "projectid"=>62698, "last"=>0, "project_name"=>"Zhoushan Peninsula Bridge Project: Phase I", "l_project_name"=>"ZHOUSHAN PENINSULA BRIDGE PROJECT: PHASE I", "region_id"=>16, "province_id"=>34, "city_id"=>1118, "l_province"=>"浙江省", "l_town"=>"舟山市", "country_id"=>8, "town_id"=>nil, "address"=>nil, "l_address"=>nil, "created_at"=>"2007-10-09T14:10:56+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:56+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"A total of two, 4-lane, 21.5-meter-wide bridges: \r\n\r\n* Xiangjiaomen Bridge will connect Fuchi Island and Lidiao Island\r\n* Cengang Bridge will connect Cengang to Fuchi Island", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"A total of two, 4-lane, 21.5-meter-wide bridges: \r\n\r\n<li> Xiangjiaomen Bridge will connect Fuchi Island and Lidiao Island\r\n<li> Cengang Bridge will connect Cengang to Fuchi Island", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35782, "projectid"=>62699, "last"=>0, "project_name"=>"Shanghai New International Exposition Center", "l_project_name"=>"SHANGHAI NEW INTERNATIONAL EXPOSITION CENTER", "region_id"=>16, "province_id"=>32, "city_id"=>894, "l_province"=>"上海", "l_town"=>"浦东新区", "country_id"=>8, "town_id"=>nil, "address"=>"Huamu", "l_address"=>"Huamu", "created_at"=>"2007-10-09T14:10:57+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:57+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>4, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"An exposition center on a 170,000-square-meter site to comprise:\r\n\r\n* an indoor exhibition area with 200,000 square meters of floor space\r\n* an outdoor exhibition area with 50,000 square meters of floor space\r\n* a conference center\r\n* a car park", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"An exposition center on a 170,000-square-meter site to comprise:\r\n\r\n<li> an indoor exhibition area with 200,000 square meters of floor space\r\n<li> an outdoor exhibition area with 50,000 square meters of floor space\r\n<li> a conference center\r\n<li> a car park", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35783, "projectid"=>62700, "last"=>0, "project_name"=>"Public Green Area", "l_project_name"=>"Public Green Area", "region_id"=>16, "province_id"=>32, "city_id"=>881, "l_province"=>"Shanghai", "l_town"=>"黄浦区", "country_id"=>8, "town_id"=>nil, "address"=>"Junction of Yanan East Road and Chendu Road", "l_address"=>"Junction of Yanan East Road and Chendu Road", "created_at"=>"2007-10-09T14:10:57+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:57+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"A 230,000-square-meter green area. The development will include pavillions and related facilities. This public green area is divided into three blocks:\r\n\r\n* Huangpu Block\r\n* Jingan Block\r\n* Luwan Block", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"A 230,000-square-meter green area. The development will include pavillions and related facilities. This public green area is divided into three blocks:\r\n\r\n<li> Huangpu Block\r\n<li> Jingan Block\r\n<li> Luwan Block", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35784, "projectid"=>62701, "last"=>0, "project_name"=>"Tsinghua Design Center", "l_project_name"=>"TSINGHUA DESIGN CENTER", "region_id"=>13, "province_id"=>3, "city_id"=>42, "l_province"=>"Beijing", "l_town"=>"海淀区", "country_id"=>8, "town_id"=>nil, "address"=>"Tsinghua University,", "l_address"=>"Tsinghua University,", "created_at"=>"2007-10-09T14:10:58+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:58+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>nil, "postcode"=>"100084", "class_type"=>nil, "local_remarks"=>"A four-storey building to contain offices for the use of Tsinghua design institute. There will be 6,800 square meters of floor space. ", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"A four-storey building to contain offices for the use of Tsinghua design institute. There will be 6,800 square meters of floor space. ", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35785, "projectid"=>62702, "last"=>0, "project_name"=>"Tsinghua Student Canteen", "l_project_name"=>"TSINGHUA STUDENT CANTEEN", "region_id"=>13, "province_id"=>3, "city_id"=>42, "l_province"=>"北京", "l_town"=>"海淀区", "country_id"=>8, "town_id"=>nil, "address"=>"Tsinghua University", "l_address"=>"Tsinghua University", "created_at"=>"2007-10-09T14:10:58+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:58+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>nil, "postcode"=>"100084", "class_type"=>nil, "local_remarks"=>"A three-storey student canteen to contain 13,300 square meters of floor space.", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"A three-storey student canteen to contain 13,300 square meters of floor space.", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35786, "projectid"=>62703, "last"=>0, "project_name"=>"Juyuan Jianingfang(Phase 2)", "l_project_name"=>"Juyuan Jianingfang(Phase 2)", "region_id"=>16, "province_id"=>32, "city_id"=>893, "l_province"=>"Shanghai", "l_town"=>"嘉定区", "country_id"=>8, "town_id"=>nil, "address"=>"Jianingfang,", "l_address"=>"Jianingfang", "created_at"=>"2007-10-09T14:10:58+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:58+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"A total of five, 6-storey residential blocks to contain 15,000 square meters of floor space.", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"A total of five, 6-storey residential blocks to contain 15,000 square meters of floor space.", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35787, "projectid"=>62704, "last"=>0, "project_name"=>"Changchun International Conference And Exhibition Center", "l_project_name"=>"长春国际会议与展览中心", "region_id"=>13, "province_id"=>9, "city_id"=>649, "l_province"=>"吉林省", "l_town"=>"长春市", "country_id"=>8, "town_id"=>nil, "address"=>"Changchun Economic and Technological Development Zone", "l_address"=>"Changchun Economic and Technological Development Zone", "created_at"=>"2007-10-09T14:10:58+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:58+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>8, "project_status_id"=>nil, "postcode"=>nil, "class_type"=>nil, "local_remarks"=>"An 83,000-square-meter development, on a 43-hectare site, is to contain:\r\n\r\n* a conference and exhibition area\r\n* a technology museum \r\n* related facilites", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"An 83,000-square-meter development, on a 43-hectare site, is to contain:\r\n\r\n<li> a conference and exhibition area\r\n<li> a technology museum \r\n<li> related facilites", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>, #<Reach::Project {"id"=>35788, "projectid"=>62705, "last"=>0, "project_name"=>"Tsinghua Biological & Medical Academic Building", "l_project_name"=>"TSINGHUA BIOLOGICAL & MEDICAL ACADEMIC BUILDING", "region_id"=>13, "province_id"=>3, "city_id"=>42, "l_province"=>"Beijing", "l_town"=>"海淀区", "country_id"=>8, "town_id"=>nil, "address"=>"Tsinghua University,", "l_address"=>"Tsinghua University,", "created_at"=>"2007-10-09T14:10:58+08:00", "created_by"=>0, "updated_at"=>"2007-10-09T14:10:58+08:00", "updated_by"=>0, "production_stage_id"=>1, "project_stage_id"=>2, "project_status_id"=>nil, "postcode"=>"100084", "class_type"=>nil, "local_remarks"=>"A four-storey acadamic building to contain lecture rooms, research rooms and other facilities. There will be 20,000 square meters of floor space.", "lastpublished"=>"2007-06-30T00:00:01+08:00", "local_remarks_text"=>"A four-storey acadamic building to contain lecture rooms, research rooms and other facilities. There will be 20,000 square meters of floor space.", "l_country"=>"中国", "info_project_status"=>"已发布", "link_status"=>0}>]....>
r.each{|rr| p rr.firm_tenders.first}
这时不会去内网,因为第一次加载的时候已经将关系数据写进redis了, 同时也是支持多层嵌套的
Reach::SubFirm.includes(:sub_contacts => [:crm_phones])
=> #<Reach::SubFirm::RopeRelation: records: [#<Reach::SubFirm {"id"=>2, "l_firm_name"=>"我的测试", "bid_tender_alias"=>nil}>, #<Reach::SubFirm {"id"=>3, "l_firm_name"=>"高正行建筑科技(上海)有限公司北京分公司", "bid_tender_alias"=>nil}>, ...
关于joins
在一个模型对另一个模型声明关系后,除了includes之外还可以join
Reach::SubFirm.joins(:sub_contacts).where("sub_contacts.id > 10")
=> #<Reach::SubFirm::RopeRelation: records: [#<Reach::SubFirm {"id"=>2, "l_firm_name"=>"我的测试", "bid_tender_alias"=>nil}>, #<Reach::SubFirm {"id"=>3, "l_firm_name"=>"高正行建筑科技(上海)有限公司北京分公司", "bid_tender_alias"=>nil}>, #<Reach::SubFirm {"id"=>3, "l_...
假如你想要在一次查询里取另外一张表的数据,你可以这样
Reach::SubFirm.joins(:sub_contacts).where("sub_contacts.id > 10").select("sub_firms.id, sub_contacts.id as other_column")
然后在你SubFirm的模型里加上
class Reach::SubFirm < Reach::Rope
has_many :sub_contacts, :class_name => 'Reach::SubContact', :foreign_key => :sub_firm_id
has_many :crm_phones, :class_name => 'Reach::CrmPhone', :foreign_key => :ref_id, :conditions => [:ref_type => 'Firm'], :order => 'created_at desc'
set_table_name 'sub_firms'
constant_in_reach "SubFirm"
reach_columns :id, :l_firm_name, :bid_tender_alias
excess_columns :other_column
end
=> #<Reach::SubFirm::RopeRelation: records: [#<Reach::SubFirm {"id"=>2, "l_firm_name"=>nil, "bid_tender_alias"=>nil, "other_column"=>29082}>, #<Reach::SubFirm {"id"=>3, "l_firm_name"=>nil, "bid_tender_alias"=>nil, "other_column"=>44377}>, #<Reach::SubFirm {"id"=>...
关于懒加载的应用
q = Reach::Project.where("created_at > '2014-01-01 00:00' ")
q = q.where(:projectid => params[:projectid]) if #一些条件
q = q.where(:last => params[:last]) if #一些条件
...
q = q.page(params[:page]).per_page(20).includes(:firm_tenders, :project_news)
你不必担心会重复查询,因为只有对它进行迭代后才会去查询
控制台里会直接查询,因为inspect被改写了
def inspect
to_a
if @records.count >= 10
"#<#{self.class}: records: #{self.instance_variable_get(:@records[0..9]).to_s + '....'}>"
else
"#<#{self.class}: records: #{self.instance_variable_get(:@records)}>"
end
end
不想要可以注掉
由于时间原因,本次rope2.0开发到此截止,关于has_one, belongs_to等等功能,可以期待3.0的到来
网友评论