开发者

Using a different database user for a single request in DataMapper

I'm working on a Rails 3 application that makes calls to a legacy database that has a very rigid permissions structure. Record visibility is set per database user, so when vi开发者_开发技巧ewing restricted records, I need to use the user's credentials to make the select request.

I can use DataMapper.setup to change the user I'm connected with, but the problem is that this is not request specific: it sets it for all requests coming in.

How can I set DataMapper to use a specific database user for a single or small set of queries, while not affecting the rest of the application?


Have you tried using multiple data-store connections? e.g.

DataMapper.setup(:default, "oracle:://user1:password1@host")
DataMapper.setup(:restricted, "oracle://user2:password2@host")

You can then use the default connection as normal, and use the restricted connection by wrapping code in a block:

DataMapper.repository(:restricted) {
  Person.first
}

More information can be found on http://datamapper.org/docs/misc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜