logo
down
shadow

Grails does not fill in foreign-key field for one-to-many relation


Grails does not fill in foreign-key field for one-to-many relation

By : SCPO
Date : November 22 2020, 02:59 PM
this will help To avoid the join table use belongsTo to create a reference from ChangeRemark to Foo.
code :
class Foo {

  static hasMany = [remarks: ChangeRemark]

}

class ChangeRemark {

  String remark
  String name

  static belongsTo = [foo: Foo]
}
ChangeRemark remark = new ChangeRemark(remark:"test", name:"t")
ChangeRemark remark2 = new ChangeRemark(remark:"test2", name:"y")

Foo foo = new Foo()

foo.addToRemarks(remark)
foo.addToRemarks(remark2)

foo.save(flush: true)


Share : facebook icon twitter icon
How to have Foreign Key Relation with a field that may contain Multiple Types of it?

How to have Foreign Key Relation with a field that may contain Multiple Types of it?


By : Program Java
Date : March 29 2020, 07:55 AM
This might help you Yes. Don't store the IDs of the Genres like (4,5,6) use first normal form and then you can get the referential integrity that you need.
You need a relationship table (say DVD_Genres) with 2 columns
code :
DVD_Id     Genre_Id
1            4
1            5
1            6
ABAP: How to create a foreign key relation with a non-key field?

ABAP: How to create a foreign key relation with a non-key field?


By : vrooh
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , First off, I agree with vwegerts's comments, what you're trying to do doesn't seem to make any sense.
Perhaps this would make more sense: create your own table without the MAKTX field. Then create a database view, joining your table and the MAKT table (and set a default language in the selection conditions if you want to). This way you'll have the descriptions joined with your data, without duplicating the actual data (which is what it looks like you're trying to do).
how to fill field foreign key from field auto_increment

how to fill field foreign key from field auto_increment


By : 日寸九日
Date : March 29 2020, 07:55 AM
Any of those help I don't know what $this means but PDO and mysqli implement lastInsertId function You should call to the first insertion and then store the last inserted id into variable. Assign $data2['id'] and $data3['id'] with the return value from lastInsertId method. Code:
code :
 <?php
       if($this->form_validation->run() == TRUE){
            echo 'Harap Tunggu...';
            //data akun
            $email = $this->input->post('email');
            $pass = md5($this->input->post('password'));

            //data pribadi
            $nama = $this->input->post('nama_lengkap');
            $alamat = $this->input->post('alamat');
            $tgl_lhr = $this->input->post('date');
            $no_telp = $this->input->post('no_telp');

            //data pendidikan
            $tingkat_pendidikan = $this->input->post('tingkat_pendidikan');
            $nama_institusi = $this->input->post('namainstitusi');
            $jurusan = $this->input->post('jurusan');
            $no_induk = $this->input->post('nomor_induk');
            $nilai = $this->input->post('nilai');
            $no_telpon_institusi = $this->input->post('no_institusi');

            $salt = $this->salt();

            $pass = $this->makePassword($this->input->post('password'), $salt);


            $data = array(
                'id' => $id,
                'email' => $email,
                'password' => $pass,
                'salt' => $salt
            );

            $data2 = array(
                'nama_lengkap' => $nama,
                'tanggal_lahir' => $tgl_lhr,
                'alamat' => $alamat,
                'no_telpon' => $no_telp,
                'id' => $id // Undefined
                );

            $data3 = array(
                'tingkat_pendidikan' => $tingkat_pendidikan,
                'nama_institusi' => $nama_institusi,
                'jurusan' => $jurusan,
                'no_induk' => $no_induk,
                'nilai' => $nilai,
                'no_telpon_institusi' => $no_telpon_institusi,
                'id' => $id // Undefined
                );


            $this->db->insert('user',$data);
            $id = $this->db->insert_id();
            $data2['id'] = $data3['id'] = $id;
            $this->db->insert('data_pribadi',$data2);
            $this->db->insert('pendidikan',$data3);

            $this->session->set_flashdata("success","your account has been created");
            $this->session->set_flashdata('id', $id);
            redirect('upload_foto/index','refresh');

        }
Getting a queryset using a foreign key field in the "other side" of a foreign key relation

Getting a queryset using a foreign key field in the "other side" of a foreign key relation


By : MreS
Date : March 29 2020, 07:55 AM
Hope this helps I'm not sure if I understood exactly what you are trying to do, but in general, while querying, you can follow relations using double underscores. Below are a couple of possible queries:
code :
my_group_header = UserGroupHeader.objects.get(...)
Category.objects.filter(usergroupdetail__usergroupheader=my_group_header) # Gets Category objects related to my_group_header through UserGroupDetail model

Category.objects.filter(usergroupdetail__usergroupheader__code='abc') # Gets Category objects related to UserGroupHeader object with code 'abc' through UserGroupDetail model

UserGroupHeader.objects.filter(usergroupdetail__category__code='abc') # Gets UserGroupHeader objects related to Category object with code 'abc' through UserGroupDetail model
Entity Framework - Main table with two users with different name field, relation with a single field of foreign key

Entity Framework - Main table with two users with different name field, relation with a single field of foreign key


By : user3079476
Date : March 29 2020, 07:55 AM
wish helps you I'm using a EF with .Net Core 2.2. And I cannot figurated out how to solve the following problem: , I solved the problem... on main table I included:
code :
[ForeignKey("PM")]
public User PmUser { get; set; }
[ForeignKey("PQL")]
public User PqlUser { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<ProjectHeader>().HasOne(m => m.PmUser).WithMany().OnDelete(DeleteBehavior.ClientSetNull);
    modelBuilder.Entity<ProjectHeader>().HasOne(m => m.PqlUser).WithMany().OnDelete(DeleteBehavior.ClientSetNull);
}
shadow
Privacy Policy - Terms - Contact Us © animezone.co