我正试图在我正在制作的网站上建立一个朋友网络。 我正在使用Mongoid。 我如何直觉朋友?
我认为,用户需要与其他多个用户建立关系联系。 但以下法典:
class User
include Mongoid::Document
references_many :users, :stored_as=>:array, :inverse_of=> :users
end
我告诉我,我有了一个无效的问题。 我做了什么错误? 没有人就如何获得我所期待的东西提出建议?
我正试图在我正在制作的网站上建立一个朋友网络。 我正在使用Mongoid。 我如何直觉朋友?
我认为,用户需要与其他多个用户建立关系联系。 但以下法典:
class User
include Mongoid::Document
references_many :users, :stored_as=>:array, :inverse_of=> :users
end
我告诉我,我有了一个无效的问题。 我做了什么错误? 没有人就如何获得我所期待的东西提出建议?
显然,经过大量研究后,Mongoid目前无法进行周期性分配,尽管它按照需要加以标示,并可能在未来版本中确定。 我目前的工作情况如下:
class User
include Mongoid::Document
field :friends, :type => Array, :default => []
def make_friends(friend)
self.add_friend(friend)
friend.add_friend(self)
end
def friends
ids = read_attribute :friends
ids.map { |id| User.find(id)}
end
def is_friends_with? other_user
ids = read_attribute :friends
ids.include? other_user.id
end
protected
def add_friend(friend)
current = read_attribute :friends
current<< friend.id
write_attribute :friends,current
save
end
end
答案是,你不能。 Mongo 亚洲开发银行没有加入表格的概念,也没有加入。 Mongoid 有许多对手的“模拟”是通过在双方储存一系列外国钥匙来实现的。
针对一项评论:Mongo 亚洲开发银行是一个文件库。 因此,它适用于“文件”差异很大的情况。 当你用坎普斯和广告的子树储存你的变压器时,你将不得不在废墟中为变压器收集广告。 如果你的数据形式非常一致,那么你可以考虑使用一个关系数据库。 我们经常使用MySQL作为相关物体,然后将MongoDB文件添加到这些物体中,以便它们能够被没收。
collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...
We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...
As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...
I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?
I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...
I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml
guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...
I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...