JavaScript 如何实现 Twitter 的 following 功能?

idlesong · April 07, 2015 · Last by flowerwrong replied at April 07, 2015 · 2228 hits

最近在学习用 Emberjs 写一个 twitter 的 following 功能,类似 rails 中的(www.railstutorial.org/book/following_users):

class CreateRelationships < ActiveRecord::Migration
  def change
    create_table :relationships do |t|
      t.integer :follower_id
      t.integer :followed_id

      t.timestamps null: false
    end
    add_index :relationships, :follower_id
    add_index :relationships, :followed_id
    add_index :relationships, [:follower_id, :followed_id], unique: true
  end
end

但是看了 Ember data 的 常见 association,没有发现什么好的实现的方案,google 了半天也没有什么头绪。请问大家该如何实现,或者有什么资料可以参考?

参考: https://github.com/fnando/has_friends

另外,这和 Ember 有何关系,这是数据库设计的问题

非常感谢。Ember data 提供了一套像 has_many, belongs_to 的 association,而且现在也提供了各数据库的 Adapter,所以不懂数据库也可以用,但是像 follow 这种复杂的就不知道怎么实现了。

You need to Sign in before reply, if you don't have an account, please Sign up first.