`
gigix
  • 浏览: 352837 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

don't use join table

阅读更多
有“播放室”和“用户”两个模型。一个播放室可以有多个用户在里面,一个用户可以参加多个播放室,于是得到了一个多对多的关系。然而继续分析下去,就把中间没有意义的rooms_users表变成了一个Attending对象。于是就得到了这样美丽的代码:

ruby 代码
  1. attending = user.attend(room)  

随后Attending对象的属性、行为也慢慢出现了。

可能大多数时候,多对多关系都可以拆分成两个一对多关系,并把原本没有意义的连接表变成一个模型对象。

另一个类似的:可能大多数时候,控制器只需要7种基本行为就够了,多余的行为可以描述为对另一种资源的基本操作。例如login实际上是session资源的create操作。
分享到:
评论
9 楼 BirdGu 2006-12-22  
join-table是一种实现手段。关联关系是否具有属性和行为这是一个建模的问题。“因为不用join-table,所以关联关系的属性和行为就浮现出来了。”,这样的表述好像有些顺序问题吧。

另外,把login当成create session,真的是个好注意吗?
8 楼 李超群 2006-12-21  
ruby 代码

   1. attending = user.attend(room) 

这段代码有点问题。

既然要把attending提炼成关系,代码一定是

attending = Attending.create(params[:attending])

而params[:attending]也就是一个map了。:user=>1,:room=>2
7 楼 刑天战士 2006-12-06  
这个就要看需求了,其实先写个多对多,然后再重构也不失为一种办法
6 楼 dongbin 2006-12-02  
DHH的PPT上说status作模型也不错,比如attended,viewed
5 楼 partech 2006-12-02  
是啊,视野决定观点
4 楼 springhill 2006-12-02  
嗯,就像use case一样,是个视角的问题,看你更关心什么了,关心user,当然要user.attend(room)啦
3 楼 partech 2006-12-02  
我喜欢
attendance = new Attendance(user,room);
2 楼 cookoo 2006-12-02  
用attendance比较好啊,attending当名词好像是医院里的大夫
1 楼 aardvark 2006-12-02  
完全视乎具体需要。如果盲目扩展join table,结果就是所谓的over-design。

其实大多数情况下join table就够了。

相关推荐

    微软内部资料-SQL性能优化5

    Having useful indexes speeds up finding individual rows in a table, as well as finding the matching rows needed to join two tables. What You Will Learn After completing this lesson, you will be able ...

    MyBatisCodeHelper-Pro.zip

    Generate mybatis sql based on mybatis interface method name like spring data jpa, with this, you don't have to write most sql for non join query support generate statement with if test Database ...

    intellitamper

    Thanks for your support and don't forget to join the forum ! 1.8 The little ToDo list ------------------------ Here are some future options, if you have new ideas... - Discover the real name ...

    FastReport.v4.9.81 for.Delphi.BCB.Full.Source企业版含ClientServer中文修正版

    FastReport doesn't use any additional DLLs, and can be compiled into your application. Powerful and flexible: A wide range of objects used in report (text, image, chart, barcode, etc.) and data-...

    CE中文版-启点CE过NP中文.exe

    Mainly minor improvements and some small bugfixes, but also a new 'ultimap like' feature called Code Filter for which you don't need any special hardware for. (Just an extensive list of addresses) ...

    SFML.Game.Development.by.Example.178528734

    Chapter 11: Don't Touch the Red Button! – Implementing the GUI Chapter 12: Can You Hear Me Now? – Sound and Music Chapter 13: We Have Contact! – Networking Basics Chapter 14: Come Play with Us! – ...

    FastReport.v4.15 for.Delphi.BCB.Full.Source企业版含ClientServer中文修正版支持D4-XE5

    - fixed bug in ODF export with properties table:number-columns-spanned, table:number-rows-spanned - fixed bug in ODF export with the background clNone color - fixed bug in ODF export with a style of ...

    ethminer-0.16.0.dev3

    Note: In Windows, it is possible to have compiler issues if you don't specify build config. In that case use: ```sh cmake --build . --config Release ``` 5. _(Optional, Linux only)_ Install the ...

    初中英语语法(固定搭配)公式汇总(完整版).docx

    - If you are in trouble, don’t hesitate to ask for help. - He found himself in trouble after making a big mistake. #### 二十六、对某方面感兴趣 - **公式**: be interested in - **例句**: - She is ...

    jQuery完全实例.rar

    While this function is, technically, chainable - there really isn't much use for chaining against it. You can have as many $(document).ready events on your page as you like. See ready(Function) ...

Global site tag (gtag.js) - Google Analytics