datamapper

Retrieve records which have many-to-many association, using ruby and datamapper

我的未来我决定 提交于 2019-12-12 02:27:14
问题 I'm learning Sinatra, and I have read datamapper documentation and found this n to n relationship example: class Photo include DataMapper::Resource property :id, Serial has n, :taggings has n, :tags, :through => :taggings end class Tag include DataMapper::Resource property :id, Serial has n, :taggings has n, :photos, :through => :taggings end class Tagging include DataMapper::Resource belongs_to :tag, :key => true belongs_to :photo, :key => true end What I understood from the code above is

ThisMember Composite object with recursive mapping

∥☆過路亽.° 提交于 2019-12-11 21:00:00
问题 I have a question, I have a following object: public class Category { public long Id { get; set; } public string Title { get; set; } public int MaxDepth { get; set; } public virtual Category Parent { get; set; } public virtual IList<Category> ChildrenNodes { get; set; } } I'm using NHibernate to retrieve the data for this, because my list is LazyLoading , it should be remapped into CategoryDTO btw: for internal uses too. This is how to the DTO looks like... (for the example I didn't put

DataMapper all_to_json() method returning slashes

柔情痞子 提交于 2019-12-11 20:19:20
问题 I just found DataMapper for CI's built in to_json and all_to_json methods, which saved me a ton of time. How can I return relations with the result? Currently my code looks like this: $homes = new Home(); $homes->include_related('address')->get(); $homes->include_related('album')->get(); $homes->get(); $homes->set_json_content_type(); echo $homes->to_json(); However I'm only getting back the home itself, rather than the nested information. EDIT: I've found that you can simply add those fields

Doctrine 2 inject data to loaded models

纵然是瞬间 提交于 2019-12-11 15:34:36
问题 I have a Doctrine 2 model which has a relation to a file system model (MogileFS) which I've implemented using a model/mapper approach. What I'm trying to accomplish is to lazy load the non-doctrine model from a Doctrine 2 entity, and inject a mapper object into this model while doing so. Example: use Doctrine\ORM\Tools\Pagination\Paginator; $dql = "SELECT p, c FROM BlogPost p JOIN p.comments c"; $query = $entityManager->createQuery($dql) ->setFirstResult(0) ->setMaxResults(100); $paginator =

Sinatra matches params[:id] as string type, additional conversion needed to match the database id?

隐身守侯 提交于 2019-12-11 10:15:57
问题 I am using sinatra and DataMapper to access an sqlite3 database. I always get an nil when calling get(params[:id]) . But when I call get(params[:id].to_i) I can get the right record. Is there anything wrong such that I have to do the conversion explicitly? The sinatra app is simple: class Record include DataMapper::Resource property :id, Serial .... end get '/list/:id' do r = Record.get(params[:id]) ... end 回答1: Obviously this is a problem with Datamapper (if you believe it should be casting

Date format different for two calls using Orika mapper

假如想象 提交于 2019-12-11 08:18:04
问题 I am getting different date formats for two web-service calls using same mapper. By mapper I mean, map:162, ConfigurableMapper (ma.glasnost.orika.impl) The OTB call to get orders i.e. OrdersController#getOrderForUserByCode() is showing the date as "date": "2018-12-22T20:42:31+0000" . My custom call to get orders i.e. IndReportController#createAdvancedOrderSearchReport() is showing the same date as "date": 1545511351000 I am using the same code as OTB to print OrderWsDTO i.e. getDataMapper()

Trouble linking one-to-one models in DataMapper

北慕城南 提交于 2019-12-11 06:21:45
问题 Using PostgreSQL and DataMapper to build a Sinatra app, running into some problems with DataMapper (I'm very new to it, used to Rails/AR ). For every Account created, it can either be an Artist , Venue , or Fan . Only one, no combining. When the user signs up, I can create the Account instance fine, but I'm having trouble creating the account's has 1 Artist or Venue or Fan instance (for ease of conversation, we'll use Artist as the belonging model). Here's my current model declarations: class

Datamapper & connection pool logic

独自空忆成欢 提交于 2019-12-11 04:02:13
问题 So I am trying to use datamapper inside my Rails 3.2.8 app. I have a config/initializers/dm.rb where I load the database.yml hash = YAML.load(File.new("database.yml")) DataMapper.setup(:default, hash[Rails.env]) I have a pool property set in the database.yml file, but I noticed that datamapper does not use that. It has this magic number 8 which it uses, where is this number coming from? And how can I configure pool settings for datamapper. 回答1: just after DataMapper.finalize I add this for my

One-to-one DataMapper association

白昼怎懂夜的黑 提交于 2019-12-11 01:44:00
问题 I'm very new to DataMapper, and I'm trying to create models for the following scenario: I've got a number of users (with a user name, password etc.), who can also be players or referees or both (so Single Table Inheritance is not an option). The base models would be: class User include DataMapper::Resource property :id, Serial # Other user properties go here end class Player include DataMapper::Resource property :id, Serial # Other player properties go here # Some kind of association goes

Force DataMapper to disconnect from postgresql

匆匆过客 提交于 2019-12-11 01:29:48
问题 I have a test that is creating and destroying a number of databases in postgresql. In order to be able to drop a database I need to tell DataMapper to disconnect. I can't seem to find any documentation on how to do that. There is a close_connection method on DataMapper::Adapters::PostgresAdapter but it is protected and requires a connection object that I can't seem to get. Is this even possible? 回答1: DataObjects::Pooling.pools.each {|pool| pool.dispose} seems to work as long as you have only