Hey,

Have a look at the section about anonymous join models at:
http://datamapper.org/docs/associations

While the whole page is definitely worth reading, you may want to
specifically read through

Has, and belongs to, many (Or Many-To-Many)

The naming conventions in use, as well as the way you typically use
these resources are described over there.

cheers
snusnu

On Thu, Aug 5, 2010 at 17:45, Richard Conroy <[email protected]> wrote:
> On Thu, Aug 5, 2010 at 4:16 PM, deco <[email protected]> wrote:
>>
>> If I made a third model manually and called it cars_people with
>> person_id and car_id as primary keys I could add rows to it.
>> (Person.cars_people.new(params) ... I realize his may not be the
>> correct way, please advise)  But seeing as it was done "through
>> Resource" I don't know how to create them.
>>
>
> I think you are on the right track. DataMapper supports 2 kinds of join
> tables,
> anonymous and custom. For most people anonymous join tables are fine; DM
> creates the table and references in the background.
>
>>
>> My models:
>>
>> Cars
>> property :id, Serial
>> property :name, String
>> property :model, String
>> has n, :people, :through => Resource
>>
>>
>> People
>> property :id, Serial
>> property :name, String
>> property :model, String
>> has n, :people, :through => Resource
>
> The key thing here is:
> has n, :model, :through => Resource
> This signifies that you are making an anonymous join table. To make this
> a custom, non anonymous join table, you would need to code it up as a
> regular
> model like you are suggesting:
> CarsPeople
> belongs_to :people
> belongs_to :cars
> property :custom_join_table_property, Stromg
> Then in your Cars and People models you signify the Custom join table like
> so:
> has n, :people, :through => CarsPeople
> Apologies if this isn't exactly correct, and I have played it fast and loose
> with DM
> pluralization naming conventions, but I think you get the picture. The docs
> aren't
> exactly swimming with information on how to do this, but the principle is
> pretty
> straightforward and consistent.
> --
> http://richardconroy.blogspot.com
>
> --
> You received this message because you are subscribed to the Google Groups
> "DataMapper" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/datamapper?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"DataMapper" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/datamapper?hl=en.

Reply via email to