鉴于我有以下客户端哈希,是否有一个快速的ruby方式(无需编写多行脚本)来获取密钥给定我想匹配client_id?例如,如何获得密钥client_id == "2180"
?
clients = {
"yellow"=>{"client_id"=>"2178"},
"orange"=>{"client_id"=>"2180"},
"red"=>{"client_id"=>"2179"},
"blue"=>{"client_id"=>"2181"}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用SQLAlchemy的具体表继承.在声明样式模型类中,我已成功配置它.
我的代码就像:
class Entry(AbstractConcreteBase, db.Model):
"""Base Class of Entry."""
id = db.Column(db.Integer, primary_key=True, nullable=False)
created = db.Column(db.DateTime, nullable=False)
post_id = declared_attr(lambda c: db.Column(db.ForeignKey("post.id")))
post = declared_attr(lambda c: db.relationship("Post", lazy="joined"))
@declared_attr
def __tablename__(cls):
return cls.__name__.lower()
@declared_attr
def __mapper_args__(cls):
# configurate subclasses about concrete table inheritance
return {'polymorphic_identity': cls.__name__,
'concrete': True} if cls.__name__ != "Entry" else {}
class TextEntry(Entry):
"""Text and Article Entry."""
text = db.deferred(db.Column(db.Text, nullable=False))
class PhotoEntry(Entry):
"""Photo Entry."""
path = db.deferred(db.Column(db.String(256), nullable=False))
Run Code Online (Sandbox Code Playgroud)
它在shell中测试时工作正常:
>>> from models.entry import Entry
>>> …
Run Code Online (Sandbox Code Playgroud)