我正在构建一个包含以下业务逻辑的发票应用程序。
a) Place a new order for customer. (an order is a group of three related components, estimate, invoice and purchaseorder)
b) After placing an order a new estimate can be generated. an order will have only one estimate.(An estimate consist of item details)
c) With reference to an estimate of the order. an invoice can be generated. an invoice qualify for the discount of price. apart from item details, an invoice consist of some expenses.an order can contain only one invoice
d) with reference to an invoice of the order, PurchaseOrder can be generated. PurchaseOrder consist of item information about vendor purchase. an order can contain multiple PurchaseOrder.
这是我想出的数据库表设计。
虽然一切看起来都不错,但我很难决定在哪里存储属于订单的特定估算、发票或采购订单的项目列表。
我想到了几种解决方案。
Approach A : create different tables for item list for each. (estimate, invoice and purchase order)
table :estimate_item,invoice_item,purchaseorder_item.(this tables contains columns similar to that of order_item in above image).
problem: problem with this approach is all the three tables consist of identical columns storing identical information, the only difference is foreign key that will be stored.Approach B: create one item list table
order_item
tablename:order_item
problem: not sure what to store as foreign key in this table since the foreign key can be from three different table. i thought of few way of handling foreign keys in this table as follows.1)foreignKey table reference column: type (example values: estimate, invoice, purchaseorder) foreignKey column: type_id(consist of foreignKey of any of three tables)
problem: i am using naming convention for column names for example column name ending withtablename_iddefines the foreign key. and this method violate the rules.2) foreignKeyColumn:
order_id,estimate_id,invoice_id,purchaseorder_id.
problem: unnecessary foreign key columns defined.
我想知道我应该如何将外键存储在 order_item 表中,以便它识别订单以及它所属的估算/发票/采购订单。
表的关系是:
idis the primary key for all the tables
table name: order relates to (contact, estimate, invoice, shipment) tables.
column name: contact_id (foreign key(referring to id column of the contact table)).
column name: estimate_id (foreign key(referring to id column of the estimate table)).
column name: invoice_id (foreign key(referring to id column of the invoice table)).
column name: shipment_id (foreign key(referring to id column of the shipment table)).
tablename: purchaseorder (this have one to many relationship with order table)
column name: order_id (foreign key(referring to id column of the order table)).
column name: contact_id (foreign key(referring to id column of the contact table)).
问题是关于如何在 order_item 表中存储外键。
谢谢。
更新 1:
请注意,每个表 estimate 、invoice 和 purchaseorder 都有自己的项目并且彼此没有关系。
最佳答案
嗨,我不确定这种关系是如何发生的。例如,您将“估计”指向“订单项目”,但我看不到您必须使用什么键才能进行连接(或查找)。作为另一个“命令”指向“估计”但是这两个是如何加入的?我没有看到这两个实体具有的任何共享属性。
我假设“id”只是使每个特定表中的行唯一的东西,而不是对应用程序有值(value)的 id。所以,我认为您需要将 estimate.reference number 携带到“order item”表中。这只是一个粗略的评论。
另外,如果键列在最前面,为了清楚起见会有所帮助。所以在'order item'中,你有属性'order id'(看起来是FK)埋在其他属性列表的末尾。使这很难阅读。
关于mysql - 关于我的业务逻辑的数据库设计,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10361504/
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我将应用程序升级到Rails4,一切正常。我可以登录并转到我的编辑页面。也更新了观点。使用标准View时,用户会更新。但是当我添加例如字段:name时,它不会在表单中更新。使用devise3.1.1和gem'protected_attributes'我需要在设备或数据库上运行某种更新命令吗?我也搜索过这个地方,找到了许多不同的解决方案,但没有一个会更新我的用户字段。我没有添加任何自定义字段。 最佳答案 如果您想允许额外的参数,您可以在ApplicationController中使用beforefilter,因为Rails4将参数
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
有时我需要处理键/值数据。我不喜欢使用数组,因为它们在大小上没有限制(很容易不小心添加超过2个项目,而且您最终需要稍后验证大小)。此外,0和1的索引变成了魔数(MagicNumber),并且在传达含义方面做得很差(“当我说0时,我的意思是head...”)。散列也不合适,因为可能会不小心添加额外的条目。我写了下面的类来解决这个问题:classPairattr_accessor:head,:taildefinitialize(h,t)@head,@tail=h,tendend它工作得很好并且解决了问题,但我很想知道:Ruby标准库是否已经带有这样一个类? 最佳
我喜欢使用Textile或Markdown为我的项目编写自述文件,但是当我生成RDoc时,自述文件被解释为RDoc并且看起来非常糟糕。有没有办法让RDoc通过RedCloth或BlueCloth而不是它自己的格式化程序运行文件?它可以配置为自动检测文件后缀的格式吗?(例如README.textile通过RedCloth运行,但README.mdown通过BlueCloth运行) 最佳答案 使用YARD直接代替RDoc将允许您包含Textile或Markdown文件,只要它们的文件后缀是合理的。我经常使用类似于以下Rake任务的东西:
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
我只想对我一直在思考的这个问题有其他意见,例如我有classuser_controller和classuserclassUserattr_accessor:name,:usernameendclassUserController//dosomethingaboutanythingaboutusersend问题是我的User类中是否应该有逻辑user=User.newuser.do_something(user1)oritshouldbeuser_controller=UserController.newuser_controller.do_something(user1,user2)我
我正在尝试使用Curbgem执行以下POST以解析云curl-XPOST\-H"X-Parse-Application-Id:PARSE_APP_ID"\-H"X-Parse-REST-API-Key:PARSE_API_KEY"\-H"Content-Type:image/jpeg"\--data-binary'@myPicture.jpg'\https://api.parse.com/1/files/pic.jpg用这个:curl=Curl::Easy.new("https://api.parse.com/1/files/lion.jpg")curl.multipart_form_
无论您是想搭建桌面端、WEB端或者移动端APP应用,HOOPSPlatform组件都可以为您提供弹性的3D集成架构,同时,由工业领域3D技术专家组成的HOOPS技术团队也能为您提供技术支持服务。如果您的客户期望有一种在多个平台(桌面/WEB/APP,而且某些客户端是“瘦”客户端)快速、方便地将数据接入到3D应用系统的解决方案,并且当访问数据时,在各个平台上的性能和用户体验保持一致,HOOPSPlatform将帮助您完成。利用HOOPSPlatform,您可以开发在任何环境下的3D基础应用架构。HOOPSPlatform可以帮您打造3D创新型产品,HOOPSSDK包含的技术有:快速且准确的CAD