English 中文(简体)
争取从一名数据申请者获得价值加入表和协会
原标题:Trying to get an value from a DataMapper join table and association

我有3个班级——米奇、米奇特和西尔。

class Mix

  include DataMapper::Resource

  property :id, Serial
  # <removed other code for brevity>

  has n, :mix_clips
  has n, :clips, :through => :mix_clips

end

class MixClip
  include DataMapper::Resource

  property :id, Serial
  property :order, Integer      

  belongs_to :mix
  belongs_to :clip
end

class Clip
  include DataMapper::Resource

  property :id, Serial
  property :title,            String    
  property :description,      Text

  has n, :mix_clips
  has n, :mixes, :through => :mix_clips
end

混杂货单与混合/单单表合并,包括外壳描述(顺序)。 我愿知道,在装满时,是否能够提一下目前的情况。

因此,我要说的是,我装上了一枚混合物和一只类似弹片:

mix = Mix.first
clip = mix.clips.first

是否有办法使“混合委员会”与这一具体的Clip有关?

clip.mix_clip.order

它通过坐在桌旁,因此我认为有办法这样做。

我知道,我只能拿到所有混合体、混合体、双壳和钻探,但我很想知道,我是否能够回头,......会比较简单。

对于那些想不到这一点的人来说,Im试图利用这一方法,因为旋转翼者在返回json/xml时确实全力支持被nes住的协会,而我也希望能够仅仅确定一种恢复数据的方法。

感谢。

问题回答

如果不修改你的法典,你就应当能够做到:

mix_clip = clip.mix_clips.first(:mix => mix, :clip => clip)

页: 1

目前,在管理部有一股ug,如果不采取任何额外措施,就会不可靠地做以下工作:

mix_clip = clip.mix_clips.get(mix.id, clip.id)

这是因为,DM忘记了关系界定的顺序,因此目前无法可靠地了解<代码>的次序。

你们可以通过在你加入的模式中明确界定外国关键特性来解决这一问题(当然,你必须明确宣布这些关系):

class MixClip
  include DataMapper::Resource

  property :id,      Serial
  property :order,   Integer      

  property :mix_id,  Integer, :key => true
  property :clip_id, Integer, :key => true

  belongs_to :mix
  belongs_to :clip
end

这将确保管理部知道<代码>。

mix_clip = clip.mix_clips.get(mix.id, clip.id)

想这样做的一个原因是,需要<代码>。





相关问题
Using Modules to Define Properties with Datamapper

so I m setting up some models and they are based off of 2 abstract base classes (or rather they used to be classes). After running into a lot of trouble with Datamapper s handling of STI for my use ...

2. 模型和制图关系

我目前正在利用模型、地图仪和控制器进行小规模应用。

Data Mapper: Is my interpretation correct?

I m trying to confirm now, what I believe about the Data Mapper pattern. So here we go: Section A: A Data Mapper is a class which is used to create, update and delete objects of another Class. ...

Reading custom data from SQL tables

We have an application that allows the user to add custom columns to our tables (maybe not the best idea, but that s how it is). We are now (re)designing our dataaccess layer (we didn t really have ...

Ruby Datamapper table inheritance with associations

I started learning Datamapper and what I liked about it was that I can write my models with real inheritance. Now I wonder, if it is possible to be more advanced about this: class Event include ...

Master / Slave switch in the Zend Framework application layer

I am writing an application which requires the Master/Slave switch to happen inside the application layer. As it is right now, I instantiate a Zend_Db_Table object on creation of the mapper, and then ...

DataMapper has n with conditions

By any chance is it possible to create a conditional association with DataMapper? For example: I want the User have n Apps just if that user have the attribute :developer => true something like ...

热门标签