This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Im trying to model a typical customer object which has physical address and a mailing address. In SQL I'd have a customer table and an address table Customer (id, physical_address_id, mailing_address_id) Address (id, street, city, etc.) I'd also have a foreign key relationship linking Customer.physical_address_id and Address.id as well as another foreign key relationsship linking Customer.mailing_address_id and Address.id.
I am trying to do this in the lightspeed model designer however the relationships seem to be defined from entity to entity not entity.propert to entity. I can use a through relationship however that does not let have only 1 billing address and 1 physical address. How should this be modelled?
|
|
|
A relationship from entity to entity implicitly defines a foreign key property, which is named for the association plus "Id" (you can override the database column name by selecting the arrow and editing the Column Name setting). That is, the relationship doesn't have to be from property to property because it creates the properties it needs. Thus, if you create a relationship from Customer to Address called "PhysicalAddress", Customer will get a PhysicalAddress property of type Address and a PhysicalAddressId property of type int. You can create a second association, say called MailingAddress, and this will give you a Customer.MailingAddressId property. In addition, if you use the Update Database feature, the designer will create foreign keys for these XxxId columns. |
|
|
Hi Ivan I cannot create two, one-to-one relationships between Customer and Address in the designer, It will allow me to create two 1-to-many relationships or one 1-to1 and one 1-to-many. It will allow me to create one 1-to-1 relationship and one 1-ThroughAssociation-1 relationship. My point is I should not need to use a ThroughAssociation for the second 1-to-1 relationship
A customer can have and must have 1 physicalAddress A customer can have 1 billingAddress but may not have one, a customer cannot have more than 1 billing address. Ultimately I want an object that has a optional BillingAddress property and a PhysicalAddress property
I should be able to write code like myCustomer.PhysicalAddress = someAddress myCustomer.BillingAddress = someBilingAddress
I should not have to write code like or myCustomer.BillingAddresses.Address = someBilingAddress myCustomer.BillingAddresses.Add(someBilingAddress)
Am I just not using the designer correctly? NOTE both relationships are in the same direction, I know the designer will let me create 1 in either drection.
|
|
|
There was a bug in LightSpeed 2.2 RTM which prevented the creation of multiple one-to-one associations in the designer. This is fixed in the latest builds. Grab a copy of the latest build from the downloads page (free edition) or the store (retail editions) and you should be able to create the two one-to-one associations you require. We apologise for the inconvenience. Note: before installing the nightly build, please manually uninstall the RTM version first (we changed our install process slightly after RTM and so nightly builds do not detect and warn if RTM is installed), otherwise you may see errors in the designer after the upgrade. |
|
|
Thank you ever so much Ivan. I can not add more than one 1-to-1 relationship. It also fixed the issue I was having with nullabilty. Changes to nullability in the designer where not flowing through into the db. I did notice one issue though, with the 1-to1 relationship, if I specified a column name that did not have the suffix "Id" ie "myColumn", the designer would create the column using the name I specified. If after the colun was created in the DB I changed any column properties ie target is nullable and tried to update the db, the sql it generated did not use the column name I specified, but rather used a name that had a suffix of "Id". Obviously the sql could not run, as no such column existed in my DB. This is not much of an issue as the designer generates sensible names if you let it do its job.
thanks again.
|
|
|
previous post shoudl read. "I can now add more than one 1-to-1 relationship" |
|