What is the name of the relation that the attribute have to the class that contains it? - theory

Theoreticaly speaking, if class A has an atribute B, B is an attribute of A, but A is what of B?

Related

OWL: scoped domain and range

What is the difference between scoped domain and domain? Also scoped range and range. And how is it defined in Protege for a single property to have two different scoped domains or scoped ranges?
P.S. I mean using two different scoped domain means:
R has range B if domain is A
R has range D if domain is C
The fact that the domain of the object property R is A could be written in this way:
R some owl:Thing SubClassOf A
The fact that the range of the object property R is B could be written in this way:
owl:Thing SubClassOf R only B
One can generalize these records slightly.
The domain of R scoped with / by B is A:
R some B SubClassOf A
The range of R scoped with / by A is B:
A SubClassOf R only B
In Protégé, one can type these axioms in these places (pressing the ⊕ button as many times as one wishes):
Active Ontology > General Class Axioms > General Class Axioms, or
Entities > Classes > [Class] > Description > General Class Axioms.
Also, the OWLAx plugin can generate both scoped and non-scoped axioms.
In DL terms, scoped domain and range axioms are:
∃R.B ⊑ A instead of ∃R.⊤ ⊑ A,
A ⊑ ∀R.B instead of ⊤ ⊑ ∀R.B.
In SWRL terms:
B(?y) ^ R(?x,?y) -> A(?x) instead of R(?x,?y) -> A(?x),
A(?x) ^ R(?x,?y) -> B(?y) instead of R(?x,?y) -> B(?y).

Django - Get related objects

I have 3 Models (lets say A, B, C). Model C has both A and B as Foreign keys. Now I have primary_key of A and I want to retrieve the list of related B objects.
I want entire object of B not just fields which I can get using values() or values_list(). My Models are as below:
class A(models.Model):
name = models.CharField(max_length=200)
description = models.CharField(max_length=200)
class B(models.Model):
name = models.CharField(max_length=200)
description = models.CharField(max_length=200)
class C(models.Model):
name = models.CharField(max_length=200)
roll_number = models.IntegerField(default=0)
a = models.ForeignKey(A,related_name='c_a')
b = models.ForeignKey(A,related_name='c_b')
You can slightly modify the answer from #Piyush S. Wanare like that:
c.objects.filter(a=primary_key_a).values('b')
Or if you only want a list with only b objects you can use values_list():
c.objects.filter(a=primary_key_a).values_list('b', flat=True)
This gives you a flat list of b (in this case). values returns a dictionary, values_list is similar but the output is a list of tuples instead of a dict. The additional option flat=True (works if only one one field is retrieved) returns a flat list of objects instead of a list of tuples of objects.
The docs for reference:
https://docs.djangoproject.com/en/1.11/ref/models/querysets/#values
https://docs.djangoproject.com/en/1.11/ref/models/querysets/#values-list

how to get model name that has m2m relation to a specific model

Suppose I have two models A and B:
class A(models.Model):
name = models.CharField()
class B(models.Model):
field = models.ManyToManyField(A)
How can I get the model name B and field from string A? or how can I get model name A and field from string B? Either is ok.
Try this out:
B._meta.get_field('field').related_model._meta.model_name

Foreign key in django returns all data from related model

I have two Model classes, A and B. B has a ForeignKey to A.
Both models have a corresponding ModelForm.
When I do this:
bbb = BForm();
for b in bbb:
print b;
If b is a ForeignKey field it prints a combobox with all data from the database (from class A).
Why?
According to Django ModelForms documentation:
ForeignKey is represented by django.forms.ModelChoiceField, which is a ChoiceField whose choices are a model QuerySet.
ChoiceField is rendered using select tag by default.

One to many relationship in JDO

In one-to-many relationship in JDO between two objects A and B, should the object B be added to the collection of B's in A separately , when only B is persisted? or does this happen automatically?
for example if A has a field:
#Persistent(mappedBy="a")
private List<B> bs= new ArrayList<B>();
and B has a field
A a;
Do I have to add objects of type B to the list in A manually or does this happen automatically?
The List owns the relation so clearly you have to add the objects to the List, otherwise they won't be in the List. A List has ordering, and if the elements aren't added to the List how can a position for each element be known?

Resources