1
我在DataMapper的總初學者,有兩種型號:DataMapper-我可以避免中間表嗎?
class ThirdPartyAccount
include DataMapper::Resource
property :access_token, String, :length => 500
belongs_to :user
end
class User
include DataMapper::Resource
property :id, Serial
property :first_name, String
has n, :third_party_accounts, :through => Resource
end
望着SQL日誌,它似乎創建兩個表 - users
,third_party_accounts
和third_party_account_users
參加這兩項。它看起來並不需要最後一個表 - third_party_account
表只需要使用它的user_id
字段直接映射到user
表?我在這裏意外創建了一個多對多的關係嗎?
完美,謝謝。不知道我在哪裏閱讀'''Resource'''的東西 - 儘管我很熟悉SQL和大多數語言,但顯然還是有一些DataMapper需要解析的語義。 – Alastair