Yii Framework Forum: Curious How To Store This Data - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Curious How To Store This Data Rate Topic: -----

#1 User is offline   AustinGeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 22-September 12

Posted 06 December 2012 - 12:31 AM

I have a model of a client.
One attribute they have is membership to an club.
Any one client can be a member of 1,2...10 clubs.

I could do create a table for client_club (client_id, club_id)
But I am curious if it is possible to store this as an array in one column of the client table.

Client
(id int
,name varchar(50)
,club array( club_id)
);

Any suggestions?

Thanks!
0

#2 User is offline   alirz23 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,079
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 06 December 2012 - 01:39 AM

you can use a text field and save it as comma separated values, or alternatively you can save it as a json object.
0

#3 User is offline   kiran sharma 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 493
  • Joined: 21-May 11
  • Location:India

Posted 06 December 2012 - 03:19 AM

From normalization point of view,
store different row for different club for different client.

client_id club_id
1------------>1
1------------>2
1------------>3
2------------>2
2------------>3

and so on..
Thanks,
Kiran Sharma.
0

#4 User is offline   fouss 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 394
  • Joined: 05-October 10
  • Location:Bamako Mali

Posted 06 December 2012 - 12:32 PM

View PostAustinGeek, on 06 December 2012 - 12:31 AM, said:

I have a model of a client.
One attribute they have is membership to an club.
Any one client can be a member of 1,2...10 clubs.

I could do create a table for client_club (client_id, club_id)
But I am curious if it is possible to store this as an array in one column of the client table.

Client
(id int
,name varchar(50)
,club array( club_id)
);

Any suggestions?

Thanks!

"A picture is worth a thousand words"
Posted Image
Posted Image
0

#5 User is offline   AustinGeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 22-September 12

Posted 07 December 2012 - 01:30 AM

View Postalirz23, on 06 December 2012 - 01:39 AM, said:

you can use a text field and save it as comma separated values, or alternatively you can save it as a json object.



Thanks Alirz23,

I was thinking comma seperated values but json might be a better option...I am new to the json manipulation but was just curious if anyone was doing anything similiar.

I will play with it...

Thanks again!
0

#6 User is offline   AustinGeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 22-September 12

Posted 07 December 2012 - 01:33 AM

View Postfouss, on 06 December 2012 - 12:32 PM, said:

"A picture is worth a thousand words"
Posted Image



Thanks Fouss

Maybe better would be Client ---< Client_Club >--- Club

As I only want one Client record.

Just was curious if the club data could be embedded into the Client.

I will have to experiment a bit with JSON.
0

#7 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,670
  • Joined: 04-March 10
  • Location:UK

Posted 07 December 2012 - 04:39 AM

I'd definitely use a separate joining table and a many-many relationship. That way you can join the tables together directly in queries and make use of the database engine's query optimisations.

You can also navigate from client to club and from club to client easily. Using json, you'd have trouble navigating both ways.
0

#8 User is offline   AustinGeek 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 173
  • Joined: 22-September 12

Posted 08 December 2012 - 11:23 PM

View PostKeith, on 07 December 2012 - 04:39 AM, said:

I'd definitely use a separate joining table and a many-many relationship. That way you can join the tables together directly in queries and make use of the database engine's query optimisations.

You can also navigate from client to club and from club to client easily. Using json, you'd have trouble navigating both ways.


Thanks Keith ! That is what I would do in the Oracle world where I normally live...Just learning this Yii stuff, but it is pretty cool!
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users