Book,Movie,Album many-to-many Pictures, How to implement therelationship about it?

This is a discussion on Book,Movie,Album many-to-many Pictures, How to implement therelationship about it? within the Object forums in Theory and Concepts category; Daniel Pitts wrote: >> class Book < ActiveRecord::Base >> has_many :book_covers > Isn't that exactly what you were asking for? Letting the framework > manage the relationship, so you don't have to? Yet has_many only manages at the syntactic level; it can't (easily) manage the semantic meaning of the relationship... -- Phlip...

Go Back   Application Development Forum > Theory and Concepts > Object

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #11  
Old 08-14-2008, 09:09 PM
Phlip
Guest
 
Default Re: Book,Movie,Album many-to-many Pictures, How to implement therelationship about it?

Daniel Pitts wrote:

>> class Book < ActiveRecord::Base
>> has_many :book_covers


> Isn't that exactly what you were asking for? Letting the framework
> manage the relationship, so you don't have to?


Yet has_many only manages at the syntactic level; it can't (easily) manage the
semantic meaning of the relationship...

--
Phlip
Reply With Quote
  #12  
Old 08-14-2008, 09:32 PM
Vince
Guest
 
Default Re: Book,Movie,Album many-to-many Pictures, How to implement therelationship about it?

On Aug 14, 11:00*pm, Daniel Pitts
<newsgroup.spamfil...@virtualinfinity.net> wrote:
> Vince wrote:
> > to Phlip,Paperclip is good for attachment,that's what I need
> > too,thanks again.

>
> > to Daniel
> > class Book < ActiveRecord::Base
> > * * has_many :book_covers
> > end

>
> > means Book extends ActiveRecord::Base(a persistence pattern
> > implementation) and one book instance can have many book covers.
> > has_many and belongs_to methods are pretty much like some contracts,it
> > makes the framework to manage the relationship(both in database and
> > logic models) between objects rather than you do it by yourself.

>
> Isn't that exactly what you were asking for? Letting the framework
> manage the relationship, so you don't have to?
> --
> Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>


That's not I ask for. Infact is more like because rails do too much
works and the cost of it is some freedom have been losed.
you know, when you get some benefits,you should pay for it.
Reply With Quote
  #13  
Old 08-14-2008, 10:09 PM
Vince
Guest
 
Default Re: Book,Movie,Album many-to-many Pictures, How to implement therelationship about it?

On Aug 14, 6:45*pm, "S Perryman" <a...@a.net> wrote:
> "Vince" <kaizen....@gmail.com> wrote in message
>
> news:ba11e225-3ee1-4e09-a4e2-3db5805a3f4c@1g2000pre.googlegroups.com...
>
> > Hi,All ! There had a design problem really bother me.
> > I had four models
> > Book,Movice,Album and Picture
> > Book,Movice and Album each of them could have many of pictures.
> > now I had three approches to build relationship bewteen them.

>
> The most general model I could think of is :
>
> * * * * * * * * * * * * * * * * * * * * * *0..1
> * * * * * * * * * * * * * * Index -------- Description
> * * * * * * * * * * |
> ImageCollection ---------- *Image
> * * * * * * * **
>
> ImageCollection :
>
> + elements : 1..MAX
> + title : string
>
> IC1 : FORALL e IN Index : e <= elements
>
> Now we can do suitable definitions ...
>
> ImageCollection <I--- BookCover
> ImageCollection <I--- Picture
> ImageCollection <I--- Movie
>
> BookCover :
>
> BC1 : elements IN [2,4]
> BC2 : outside-front = Image.Index(1)
> BC3 : outside-back = Image.Index(2)
> BC4 : inside-left = Image.Index(3)
> BC5 : inside-right = Image.Index(4)
>
> Picture :
>
> P1 : elements = 1
> P2 : image = Image.Index(maximum)
>
> Movie (30fps etc) :
>
> * running-time (seconds) 1..N
>
> M1 : elements <= 30 * running-time
>
> Regards,
> Steven Perryman


Now I found one-to-many is more appropriate.
Book ---1:*---- Picture or Book ---1:1---BookCover---1:*---Picture
Album ---1:*---- Picture or Album ---1:1---AlbumCover---1:*---Picture
If the relationship like above,How to contact them in database layer.

If use joining table,I think that would be more appropriate for many
to many relationship.
If I add a column 'resource_id' into Picture table to build the
relationship, whether I also need to add a 'resource_type' column to
defferentiate the type of these ids.
Reply With Quote
  #14  
Old 08-15-2008, 03:07 AM
S Perryman
Guest
 
Default Re: Book,Movie,Album many-to-many Pictures, How to implement the relationship about it?

"Vince" <kaizen.Liu@gmail.com> wrote in message
news:58a61698-483a-4434-b4ac-ae6eeec3b07e@r15g2000prd.googlegroups.com...

On Aug 14, 6:45 pm, "S Perryman" <a...@a.net> wrote:
> "Vince" <kaizen....@gmail.com> wrote in message


[ model snipped ... ]

> Now I found one-to-many is more appropriate.
> Book ---1:*---- Picture or Book ---1:1---BookCover---1:*---Picture
> Album ---1:*---- Picture or Album ---1:1---AlbumCover---1:*---Picture
> If the relationship like above,How to contact them in database layer.


> If use joining table,I think that would be more appropriate for many
> to many relationship.
> If I add a column 'resource_id' into Picture table to build the
> relationship, whether I also need to add a 'resource_type' column to
> defferentiate the type of these ids.


From the model I gave you :

ImageCollection(coll_id, ...)
Image(image_id, ... )
CollectionContents(coll_id, index, description, image_id)

I don't need a 'resource type' id.
If I did (to associate invariants etc) , it would go into the
ImageCollection
relation only.


Regards,
Steven Perryman


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 07:59 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.